Search in sources :

Example 11 with HDF5File

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

the class HDF5PCACoveragePoNCreationUtilsUnitTest method testCalculateVariance.

@Test
public void testCalculateVariance() {
    /*
        This tests that the post-projection variance is correct.  Ground truth was acquired through a breakpoint (to get input values),
        some text parsing, and matlab.  This simply tests that the variances are correctly calculated from a matrix.
        */
    final int numEigensamples = 20;
    final File ponFile = PoNTestUtils.createDummyHDF5FilePoN(TEST_PCOV_FILE, numEigensamples);
    final double[] gtTargetVariances = ParamUtils.readValuesFromFile(GT_TARGET_VAR_FILE);
    try (final HDF5File ponHDF5File = new HDF5File(ponFile)) {
        final HDF5PCACoveragePoN pon = new HDF5PCACoveragePoN(ponHDF5File);
        final double[] targetVariances = pon.getTargetVariances();
        PoNTestUtils.assertEqualsDoubleArrays(targetVariances, gtTargetVariances, 1E-4);
    }
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) HDF5File(org.broadinstitute.hdf5.HDF5File) File(java.io.File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 12 with HDF5File

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

the class HDF5PCACoveragePoNUnitTest method testSampleNameReading.

@Test
public void testSampleNameReading() throws IOException {
    final HDF5File reader = new HDF5File(TEST_PON);
    final PCACoveragePoN pon = new HDF5PCACoveragePoN(reader);
    final List<String> sampleNames = pon.getSampleNames();
    final List<String> expected = readLines(TEST_PON_SAMPLES);
    Assert.assertNotNull(sampleNames);
    Assert.assertEquals(sampleNames, expected);
    reader.close();
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 13 with HDF5File

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

the class PCATangentNormalizationUtilsUnitTest method testSparkTangentNormalizeSparkVsNoSpark.

@Test
public void testSparkTangentNormalizeSparkVsNoSpark() {
    final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
    final File ponFile = PoNTestUtils.createDummyHDF5FilePoN(TEST_PCOV_FILE, 20);
    try (final HDF5File ponHDF5File = new HDF5File(ponFile)) {
        final PCACoveragePoN pon = new HDF5PCACoveragePoN(ponHDF5File);
        final PCATangentNormalizationResult tnWithSpark = pon.normalizeNormalsInPoN(ctx);
        final PCATangentNormalizationResult tnWithoutSpark = pon.normalizeNormalsInPoN();
        PoNTestUtils.assertEqualsMatrix(tnWithSpark.getTangentNormalized().counts(), tnWithoutSpark.getTangentNormalized().counts(), false);
        PoNTestUtils.assertEqualsMatrix(tnWithSpark.getPreTangentNormalized().counts(), tnWithoutSpark.getPreTangentNormalized().counts(), false);
        PoNTestUtils.assertEqualsMatrix(tnWithSpark.getTangentBetaHats(), tnWithoutSpark.getTangentBetaHats(), false);
    }
}
Also used : JavaSparkContext(org.apache.spark.api.java.JavaSparkContext) 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 14 with HDF5File

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

the class HDF5PCACoveragePoNUnitTest method testNormalizedPcovReading.

@Test(dependsOnMethods = { "testTargetNameReading", "testSampleNameReading" })
public void testNormalizedPcovReading() throws IOException {
    final HDF5File reader = new HDF5File(TEST_PON);
    final PCACoveragePoN pon = new HDF5PCACoveragePoN(reader);
    final List<String> targets = pon.getTargetNames();
    final List<String> samples = pon.getSampleNames();
    final RealMatrix actual = pon.getNormalizedCounts();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getRowDimension(), targets.size());
    Assert.assertEquals(actual.getColumnDimension(), samples.size());
    final RealMatrix expected = readDoubleMatrix(TEST_PON_NORMALIZED_PCOV);
    MathObjectAsserts.assertRealMatrixEquals(actual, expected);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 15 with HDF5File

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

the class HDF5PCACoveragePoNUnitTest method testLogNormalizedSampleNameReading.

@Test(dependsOnMethods = "testSampleNameReading")
public void testLogNormalizedSampleNameReading() throws IOException {
    final HDF5File reader = new HDF5File(TEST_PON);
    final PCACoveragePoN pon = new HDF5PCACoveragePoN(reader);
    final List<String> expected = readLines(TEST_PON_LOG_NORMAL_SAMPLES);
    final List<String> logNormalizedSampleNames = pon.getPanelSampleNames().stream().sorted().collect(Collectors.toList());
    Assert.assertEquals(logNormalizedSampleNames, expected);
}
Also used : HDF5File(org.broadinstitute.hdf5.HDF5File) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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