use of org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN 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);
}
});
}
}
use of org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN in project gatk 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);
}
});
}
}
use of org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN in project gatk by broadinstitute.
the class CreatePanelOfNormalsIntegrationTest method assertRamPoNDuplicate.
private void assertRamPoNDuplicate(final File outputFile) {
try (final HDF5File hdf5FilePoN = new HDF5File(outputFile)) {
final HDF5PCACoveragePoN filePoN = new HDF5PCACoveragePoN(hdf5FilePoN);
assertRamPoNDuplicate(filePoN);
}
}
use of org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN in project gatk 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));
}
}
}
use of org.broadinstitute.hellbender.tools.pon.coverage.pca.HDF5PCACoveragePoN 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);
}
}
}
}
Aggregations