Search in sources :

Example 86 with Array2DRowRealMatrix

use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk-protected by broadinstitute.

the class NormalizeSomaticReadCountsIntegrationTest method reorderTargetsToPoNOrder.

private RealMatrix reorderTargetsToPoNOrder(final ReadCountCollection preTangentNormalized, final List<String> ponTargets) {
    final RealMatrix preTangentNormalizedCounts = preTangentNormalized.counts();
    final Map<String, Integer> ponTargetIndex = IntStream.range(0, ponTargets.size()).boxed().collect(Collectors.toMap(ponTargets::get, Function.identity()));
    // first we need to sort the input counts so that they match the
    // target order in the PoN.
    final double[][] ponPreparedInput = new double[ponTargets.size()][];
    for (int i = 0; i < preTangentNormalizedCounts.getRowDimension(); i++) {
        final Target target = preTangentNormalized.targets().get(i);
        if (!ponTargetIndex.containsKey(target.getName()))
            continue;
        final int idx = ponTargetIndex.get(target.getName());
        ponPreparedInput[idx] = preTangentNormalizedCounts.getRow(i);
    }
    // The actual input to create the beta-hats, sorted by the PoN targets:
    return new Array2DRowRealMatrix(ponPreparedInput, false);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Example 87 with Array2DRowRealMatrix

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

the class NormalizeSomaticReadCountsIntegrationTest method reorderTargetsToPoNOrder.

private RealMatrix reorderTargetsToPoNOrder(final ReadCountCollection preTangentNormalized, final List<String> ponTargets) {
    final RealMatrix preTangentNormalizedCounts = preTangentNormalized.counts();
    final Map<String, Integer> ponTargetIndex = IntStream.range(0, ponTargets.size()).boxed().collect(Collectors.toMap(ponTargets::get, Function.identity()));
    // first we need to sort the input counts so that they match the
    // target order in the PoN.
    final double[][] ponPreparedInput = new double[ponTargets.size()][];
    for (int i = 0; i < preTangentNormalizedCounts.getRowDimension(); i++) {
        final Target target = preTangentNormalized.targets().get(i);
        if (!ponTargetIndex.containsKey(target.getName()))
            continue;
        final int idx = ponTargetIndex.get(target.getName());
        ponPreparedInput[idx] = preTangentNormalizedCounts.getRow(i);
    }
    // The actual input to create the beta-hats, sorted by the PoN targets:
    return new Array2DRowRealMatrix(ponPreparedInput, false);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix)

Example 88 with Array2DRowRealMatrix

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

the class MatrixSummaryUtilsUnitTest method testGetRowVariances.

@Test(dataProvider = "rowVarianceTestData")
public void testGetRowVariances(double[][] testdata, double[] gtRowVariances) {
    final RealMatrix tmp = new Array2DRowRealMatrix(testdata);
    PoNTestUtils.assertEqualsDoubleArrays(MatrixSummaryUtils.getRowVariances(tmp), gtRowVariances);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 89 with Array2DRowRealMatrix

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

the class MatrixSummaryUtilsUnitTest method testGetRowAndColumnMedians.

@Test(dataProvider = "rowAndColumnMedianTestData")
public void testGetRowAndColumnMedians(double[][] testdata, double[] gtRowMedian, double[] gtColumnMedian) {
    final RealMatrix tmp = new Array2DRowRealMatrix(testdata);
    PoNTestUtils.assertEqualsDoubleArrays(MatrixSummaryUtils.getRowMedians(tmp), gtRowMedian);
    PoNTestUtils.assertEqualsDoubleArrays(MatrixSummaryUtils.getColumnMedians(tmp), gtColumnMedian);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) RealMatrix(org.apache.commons.math3.linear.RealMatrix) Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Example 90 with Array2DRowRealMatrix

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

the class GATKProtectedMathUtilsTest method testColumnSum.

@Test
public void testColumnSum() {
    final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
    final double[] guess = GATKProtectedMathUtils.columnSums(new Array2DRowRealMatrix(array));
    final double[] gt = { -2, 17, 29 };
    Assert.assertEquals(guess.length, 3);
    Assert.assertEquals(guess, gt);
}
Also used : Array2DRowRealMatrix(org.apache.commons.math3.linear.Array2DRowRealMatrix) Test(org.testng.annotations.Test)

Aggregations

Array2DRowRealMatrix (org.apache.commons.math3.linear.Array2DRowRealMatrix)141 RealMatrix (org.apache.commons.math3.linear.RealMatrix)101 Test (org.testng.annotations.Test)60 IntStream (java.util.stream.IntStream)31 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)28 File (java.io.File)27 Collectors (java.util.stream.Collectors)25 ArrayList (java.util.ArrayList)24 Assert (org.testng.Assert)24 List (java.util.List)22 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)22 Target (org.broadinstitute.hellbender.tools.exome.Target)18 java.util (java.util)15 Random (java.util.Random)14 ReadCountCollection (org.broadinstitute.hellbender.tools.exome.ReadCountCollection)14 ParamUtils (org.broadinstitute.hellbender.utils.param.ParamUtils)14 DataProvider (org.testng.annotations.DataProvider)14 Stream (java.util.stream.Stream)13 Arrays (java.util.Arrays)12 DoubleStream (java.util.stream.DoubleStream)12