use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowMeans.
@Test
public void testRowMeans() {
final double[][] array = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
final double[] rowMeans = GATKProtectedMathUtils.rowMeans(new Array2DRowRealMatrix(array));
Assert.assertEquals(rowMeans, new double[] { 2, 5, 8 });
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class GATKProtectedMathUtilsTest method testRowNaN.
@Test
public void testRowNaN() {
final double[][] array = { { 1, 2, Double.NaN }, { 5, 5, 5 }, { 7, 8, 9 }, { -15, 2, 12 } };
final double[] guess = GATKProtectedMathUtils.rowSums(new Array2DRowRealMatrix(array));
final double[] gt = { Double.NaN, 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.isNaN(guess[0]));
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class HDF5PCACoveragePoNCreationUtilsUnitTest method simpleEigensampleData.
@DataProvider(name = "singleEigensample")
public Object[][] simpleEigensampleData() {
final List<Object[]> result = new ArrayList<>();
final int NUM_TARGETS = 10;
final int NUM_SAMPLES = 5;
final List<Target> targets = IntStream.range(0, NUM_TARGETS).boxed().map(i -> new Target("target_" + i, new SimpleInterval("1", 100 * i + 1, 100 * i + 5))).collect(Collectors.toList());
final List<String> columnNames = IntStream.range(0, NUM_SAMPLES).boxed().map(i -> "sample_" + i).collect(Collectors.toList());
double[][] countsArray = new double[NUM_TARGETS][NUM_SAMPLES];
final RealMatrix counts = new Array2DRowRealMatrix(countsArray);
// All row data is the same (0,1,2,3,4...)
final double[] rowData = IntStream.range(0, NUM_SAMPLES).boxed().mapToDouble(i -> i).toArray();
for (int i = 0; i < NUM_TARGETS; i++) {
counts.setRow(i, rowData);
}
new ReadCountCollection(targets, columnNames, counts);
result.add(new Object[] { new ReadCountCollection(targets, columnNames, counts) });
return result.toArray(new Object[result.size()][]);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class HDF5PCACoveragePoNCreationUtilsUnitTest method readCountOnlyWithDiverseShapeData.
@DataProvider(name = "readCountOnlyWithDiverseShapeData")
public Object[][] readCountOnlyWithDiverseShapeData() {
final List<Object[]> result = new ArrayList<>(4);
final Random rdn = new Random(31);
final int[] columnCounts = new int[] { 10, 100, 100, 200 };
final int[] targetCounts = new int[] { 100, 100, 200, 200 };
for (int k = 0; k < columnCounts.length; k++) {
final List<String> columnNames = IntStream.range(0, columnCounts[k]).mapToObj(i -> "sample_" + (i + 1)).collect(Collectors.toList());
final List<Target> targets = IntStream.range(0, targetCounts[k]).mapToObj(i -> new Target("target_" + (i + 1))).collect(Collectors.toList());
final double[][] counts = new double[targetCounts[k]][columnCounts[k]];
for (int i = 0; i < counts.length; i++) {
for (int j = 0; j < counts[0].length; j++) {
counts[i][j] = rdn.nextDouble();
}
}
final ReadCountCollection readCounts = new ReadCountCollection(targets, columnNames, new Array2DRowRealMatrix(counts, false));
result.add(new Object[] { readCounts });
}
return result.toArray(new Object[result.size()][]);
}
use of org.apache.commons.math3.linear.Array2DRowRealMatrix in project gatk by broadinstitute.
the class PCATangentNormalizationUtilsUnitTest method normalizeReadCountByTargetFactorsData.
@DataProvider(name = "normalizeReadCountByTargetFactorsData")
public Object[][] normalizeReadCountByTargetFactorsData() {
final List<Object[]> result = new ArrayList<>(1);
@SuppressWarnings("serial") final List<Target> targets = new ArrayList<Target>() {
{
add(new Target("A"));
add(new Target("B"));
add(new Target("C"));
}
};
@SuppressWarnings("serial") final List<String> columnNames = new ArrayList<String>() {
{
add("1");
add("2");
add("3");
}
};
result.add(new Object[] { new ReadCountCollection(targets, columnNames, new Array2DRowRealMatrix(new double[][] { new double[] { 1.1, 2.2, 3.3 }, new double[] { 0.1, 0.2, 0.3 }, new double[] { 11.1, 22.2, 33.3 } }, false)), new double[] { 100.0, 200.0, 300.0 } });
return result.toArray(new Object[1][]);
}
Aggregations