Search in sources :

Example 51 with RealMatrix

use of org.apache.commons.math3.linear.RealMatrix in project gatk by broadinstitute.

the class HDF5PCACoveragePoNUnitTest method testLogNormalizedPInvMatrixReading.

@Test(dependsOnMethods = { "testTargetNameReading", "testLogNormalizedSampleNameReading" })
public void testLogNormalizedPInvMatrixReading() 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.getLogNormalizedPInverseCounts();
    Assert.assertNotNull(actual);
    Assert.assertEquals(actual.getRowDimension(), samples.size());
    Assert.assertEquals(actual.getColumnDimension(), targets.size());
    final RealMatrix expected = readDoubleMatrix(TEST_PON_LOG_NORMALS_PINV);
    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 52 with RealMatrix

use of org.apache.commons.math3.linear.RealMatrix in project gatk by broadinstitute.

the class RamPCACoveragePoNUnitTest method assertReducedPanelPInverseCounts.

private void assertReducedPanelPInverseCounts(final PCACoveragePoN filePoN, final PCACoveragePoN ramPoN) {
    final RealMatrix ramNormalizedCounts = ramPoN.getReducedPanelPInverseCounts();
    final RealMatrix fileNormalizedCounts = filePoN.getReducedPanelPInverseCounts();
    Assert.assertEquals(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm(), 0, 1e-9);
    ramNormalizedCounts.setEntry(3, 4, 500000);
    Assert.assertEquals(ramNormalizedCounts.getEntry(3, 4), 500000, 1e-9);
    Assert.assertNotEquals(ramPoN.getReducedPanelPInverseCounts().getEntry(3, 4), 500000, 1e-9);
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm() < 1e-9);
    final RealMatrix fileNormalizedCounts2 = filePoN.getReducedPanelPInverseCounts();
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts2).getNorm() < 1e-9);
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 53 with RealMatrix

use of org.apache.commons.math3.linear.RealMatrix in project gatk by broadinstitute.

the class RamPCACoveragePoNUnitTest method assertLogNormalizedPinvCounts.

private void assertLogNormalizedPinvCounts(final PCACoveragePoN filePoN, final PCACoveragePoN ramPoN) {
    final RealMatrix ramNormalizedCounts = ramPoN.getLogNormalizedPInverseCounts();
    final RealMatrix fileNormalizedCounts = filePoN.getLogNormalizedPInverseCounts();
    Assert.assertEquals(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm(), 0, 1e-9);
    ramNormalizedCounts.setEntry(3, 4, 500000);
    Assert.assertEquals(ramNormalizedCounts.getEntry(3, 4), 500000, 1e-9);
    Assert.assertNotEquals(ramPoN.getLogNormalizedPInverseCounts().getEntry(3, 4), 500000, 1e-9);
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm() < 1e-9);
    final RealMatrix fileNormalizedCounts2 = filePoN.getLogNormalizedPInverseCounts();
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts2).getNorm() < 1e-9);
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 54 with RealMatrix

use of org.apache.commons.math3.linear.RealMatrix in project gatk by broadinstitute.

the class RamPCACoveragePoNUnitTest method assertNormalizedCounts.

private void assertNormalizedCounts(final PCACoveragePoN filePoN, final PCACoveragePoN ramPoN) {
    final RealMatrix ramNormalizedCounts = ramPoN.getNormalizedCounts();
    final RealMatrix fileNormalizedCounts = filePoN.getNormalizedCounts();
    Assert.assertEquals(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm(), 0, 1e-9);
    ramNormalizedCounts.setEntry(3, 4, 500000);
    Assert.assertEquals(ramNormalizedCounts.getEntry(3, 4), 500000, 1e-9);
    Assert.assertNotEquals(ramPoN.getNormalizedCounts().getEntry(3, 4), 500000, 1e-9);
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm() < 1e-9);
    final RealMatrix fileNormalizedCounts2 = filePoN.getNormalizedCounts();
    Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts2).getNorm() < 1e-9);
}
Also used : RealMatrix(org.apache.commons.math3.linear.RealMatrix)

Example 55 with RealMatrix

use of org.apache.commons.math3.linear.RealMatrix in project gatk by broadinstitute.

the class HDF5LibraryUnitTest method createMatrixOfGaussianValues.

private RealMatrix createMatrixOfGaussianValues(int numRows, int numCols, final double mean, final double sigma) {
    final RealMatrix bigCounts = new Array2DRowRealMatrix(numRows, numCols);
    final RandomDataGenerator randomDataGenerator = new RandomDataGenerator();
    randomDataGenerator.reSeed(337337337);
    bigCounts.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {

        @Override
        public double visit(int row, int column, double value) {
            return randomDataGenerator.nextGaussian(mean, sigma);
        }
    });
    return bigCounts;
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RandomDataGenerator(org.apache.commons.math3.random.RandomDataGenerator) DefaultRealMatrixChangingVisitor(org.apache.commons.math3.linear.DefaultRealMatrixChangingVisitor)

Aggregations

RealMatrix (org.apache.commons.math3.linear.RealMatrix)259 Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)158 Test (org.testng.annotations.Test)86 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)60 IntStream (java.util.stream.IntStream)50 Collectors (java.util.stream.Collectors)48 Median (org.apache.commons.math3.stat.descriptive.rank.Median)42 HDF5File (org.broadinstitute.hdf5.HDF5File)42 File (java.io.File)40 List (java.util.List)37 DefaultRealMatrixChangingVisitor (org.apache.commons.math3.linear.DefaultRealMatrixChangingVisitor)36 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)36 ArrayList (java.util.ArrayList)32 Assert (org.testng.Assert)32 IOException (java.io.IOException)30 Percentile (org.apache.commons.math3.stat.descriptive.rank.Percentile)30 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)30 DoubleStream (java.util.stream.DoubleStream)28 Logger (org.apache.logging.log4j.Logger)27 Utils (org.broadinstitute.hellbender.utils.Utils)27