use of org.broadinstitute.hdf5.HDF5File in project gatk by broadinstitute.
the class NormalizeSomaticReadCountsIntegrationTest method assertBetaHats.
/**
* Asserts that a collection of beta-hats corresponds to the expected value given
* the input pre-tangent normalization matrix and the PoN file.
*/
private void assertBetaHats(final ReadCountCollection preTangentNormalized, final RealMatrix actual, final File ponFile) {
Assert.assertEquals(actual.getColumnDimension(), preTangentNormalized.columnNames().size());
final double epsilon = PCATangentNormalizationUtils.EPSILON;
try (final HDF5File ponReader = new HDF5File(ponFile)) {
final PCACoveragePoN pon = new HDF5PCACoveragePoN(ponReader);
final List<String> ponTargets = pon.getPanelTargetNames();
final RealMatrix inCounts = reorderTargetsToPoNOrder(preTangentNormalized, ponTargets);
// obtain subset of relevant targets to calculate the beta-hats;
final int[][] betaHatTargets = new int[inCounts.getColumnDimension()][];
for (int i = 0; i < inCounts.getColumnDimension(); i++) {
final List<Integer> relevantTargets = new ArrayList<>();
for (int j = 0; j < inCounts.getRowDimension(); j++) {
if (inCounts.getEntry(j, i) > 1 + (Math.log(epsilon) / Math.log(2))) {
relevantTargets.add(j);
}
}
betaHatTargets[i] = relevantTargets.stream().mapToInt(Integer::intValue).toArray();
}
// calculate beta-hats per column and check with actual values.
final RealMatrix normalsInv = pon.getReducedPanelPInverseCounts();
Assert.assertEquals(actual.getRowDimension(), normalsInv.getRowDimension());
final RealMatrix normalsInvT = normalsInv.transpose();
for (int i = 0; i < inCounts.getColumnDimension(); i++) {
final RealMatrix inValues = inCounts.getColumnMatrix(i).transpose().getSubMatrix(new int[] { 0 }, betaHatTargets[i]);
final RealMatrix normalValues = normalsInvT.getSubMatrix(betaHatTargets[i], IntStream.range(0, normalsInvT.getColumnDimension()).toArray());
final RealMatrix betaHats = inValues.multiply(normalValues);
for (int j = 0; j < actual.getRowDimension(); j++) {
Assert.assertEquals(actual.getEntry(j, i), betaHats.getEntry(0, j), 0.000001, "Col " + i + " row " + j);
}
}
}
}
use of org.broadinstitute.hdf5.HDF5File in project gatk by broadinstitute.
the class HDF5PCACoveragePoNUnitTest method testVersionReading.
@Test
public void testVersionReading() {
final HDF5File reader = new HDF5File(TEST_PON);
final PCACoveragePoN pon = new HDF5PCACoveragePoN(reader);
Assert.assertEquals(pon.getVersion(), TEST_PON_VERSION);
reader.close();
}
use of org.broadinstitute.hdf5.HDF5File in project gatk by broadinstitute.
the class HDF5PCACoveragePoNUnitTest method testReducedPoNMatrixReading.
@Test(dependsOnMethods = { "testTargetNameReading", "testLogNormalizedSampleNameReading" })
public void testReducedPoNMatrixReading() 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.getPanelSampleNames();
final RealMatrix actual = pon.getReducedPanelCounts();
Assert.assertNotNull(actual);
Assert.assertEquals(actual.getRowDimension(), targets.size());
Assert.assertTrue(actual.getColumnDimension() <= samples.size());
final RealMatrix expected = readDoubleMatrix(TEST_PON_REDUCED_PON);
MathObjectAsserts.assertRealMatrixEquals(actual, expected);
}
use of org.broadinstitute.hdf5.HDF5File in project gatk by broadinstitute.
the class HDF5PCACoveragePoNUnitTest method testReducedPoNPInvMatrixReading.
@Test(dependsOnMethods = { "testTargetNameReading", "testLogNormalizedSampleNameReading" })
public void testReducedPoNPInvMatrixReading() 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.getPanelSampleNames();
final RealMatrix actual = pon.getReducedPanelPInverseCounts();
Assert.assertNotNull(actual);
Assert.assertTrue(actual.getRowDimension() <= samples.size());
Assert.assertEquals(actual.getColumnDimension(), targets.size());
final RealMatrix expected = readDoubleMatrix(TEST_PON_REDUCED_PON_PINV);
MathObjectAsserts.assertRealMatrixEquals(actual, expected);
}
use of org.broadinstitute.hdf5.HDF5File in project gatk 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();
}
Aggregations