use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GCBiasSimulatedData method simulatedData.
// visible for the integration test
public static Pair<ReadCountCollection, double[]> simulatedData(final int numTargets, final int numSamples) {
final List<Target> phonyTargets = SimulatedTargets.phonyTargets(numTargets);
final List<String> phonySamples = SimulatedSamples.phonySamples(numSamples);
final Random random = new Random(13);
final double[] gcContentByTarget = IntStream.range(0, numTargets).mapToDouble(n -> 0.5 + 0.2 * random.nextGaussian()).map(x -> Math.min(x, 0.95)).map(x -> Math.max(x, 0.05)).toArray();
final double[] gcBiasByTarget = Arrays.stream(gcContentByTarget).map(QUADRATIC_GC_BIAS_CURVE::apply).toArray();
// model mainly GC bias with a small random amount of non-GC bias
// thus noise after GC correction should be nearly zero
final RealMatrix counts = new Array2DRowRealMatrix(numTargets, numSamples);
counts.walkInOptimizedOrder(new DefaultRealMatrixChangingVisitor() {
@Override
public double visit(final int target, final int column, final double value) {
return gcBiasByTarget[target] * (1.0 + 0.01 * random.nextDouble());
}
});
final ReadCountCollection rcc = new ReadCountCollection(phonyTargets, phonySamples, counts);
return new ImmutablePair<>(rcc, gcContentByTarget);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowInf.
@Test
public void testRowInf() {
final double[][] array = { { 1, 2, Double.POSITIVE_INFINITY }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] guess = GATKProtectedMathUtils.rowSums(new Array2DRowRealMatrix(array));
final double[] gt = { Double.POSITIVE_INFINITY, 15, 24, -1 };
Assert.assertEquals(guess.length, 4);
Assert.assertEquals(guess[1], gt[1]);
Assert.assertEquals(guess[2], gt[2]);
Assert.assertEquals(guess[3], gt[3]);
Assert.assertTrue(Double.isInfinite(guess[0]));
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowVariances.
@Test
public void testRowVariances() {
final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 } };
final double[] rowVariances = GATKProtectedMathUtils.rowVariances(new Array2DRowRealMatrix(array));
Assert.assertEquals(rowVariances[0], 1, 1e-8);
Assert.assertEquals(rowVariances[1], 0, 1e-8);
Assert.assertEquals(rowVariances[2], 1, 1e-8);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowSum.
@Test
public void testRowSum() {
final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] guess = GATKProtectedMathUtils.rowSums(new Array2DRowRealMatrix(array));
final double[] gt = { 6, 15, 24, -1 };
Assert.assertEquals(guess.length, 4);
Assert.assertEquals(guess, gt);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowStdDevs.
@Test
public void testRowStdDevs() {
final double[][] array = { { 1, 2, 3 }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] rowStdDevs = GATKProtectedMathUtils.rowStdDevs(new Array2DRowRealMatrix(array));
Assert.assertEquals(rowStdDevs[0], 1, 1e-8);
Assert.assertEquals(rowStdDevs[1], 0, 1e-8);
Assert.assertEquals(rowStdDevs[2], 1, 1e-8);
Assert.assertEquals(rowStdDevs[3], 13.65039682, 1e-8);
}
Aggregations