use of org.apache.commons.math3.linear.RealMatrix in project gatk-protected 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.RealMatrix in project gatk-protected by broadinstitute.
the class HDF5PCACoveragePoNCreationUtilsUnitTest method testCalculateReducedPanelAndPInversesKeepingHalfOfAllColumns.
@Test(dataProvider = "readCountOnlyWithDiverseShapeData")
public void testCalculateReducedPanelAndPInversesKeepingHalfOfAllColumns(final ReadCountCollection readCounts) {
final JavaSparkContext ctx = SparkContextFactory.getTestSparkContext();
final ReductionResult result = HDF5PCACoveragePoNCreationUtils.calculateReducedPanelAndPInverses(readCounts, OptionalInt.of(readCounts.columnNames().size() / 2), NULL_LOGGER, ctx);
final RealMatrix counts = readCounts.counts();
Assert.assertNotNull(result);
Assert.assertNotNull(result.getPseudoInverse());
Assert.assertNotNull(result.getReducedCounts());
Assert.assertNotNull(result.getReducedPseudoInverse());
Assert.assertNotNull(result.getAllSingularValues());
Assert.assertEquals(counts.getColumnDimension(), result.getAllSingularValues().length);
Assert.assertEquals(result.getReducedCounts().getRowDimension(), counts.getRowDimension());
Assert.assertEquals(result.getReducedCounts().getColumnDimension(), readCounts.columnNames().size() / 2);
final int eigensamples = result.getReducedCounts().getColumnDimension();
Assert.assertEquals(eigensamples, readCounts.columnNames().size() / 2);
assertPseudoInverse(counts, result.getPseudoInverse());
assertPseudoInverse(result.getReducedCounts(), result.getReducedPseudoInverse());
}
use of org.apache.commons.math3.linear.RealMatrix in project gatk-protected by broadinstitute.
the class PCATangentNormalizationUtilsUnitTest method testNormalizeReadCountByTargetFactors.
@Test(dataProvider = "normalizeReadCountByTargetFactorsData")
public void testNormalizeReadCountByTargetFactors(final ReadCountCollection readCount, final double[] targetFactors) {
final RealMatrix before = readCount.counts().copy();
PCATangentNormalizationUtils.factorNormalize(readCount.counts(), targetFactors);
final RealMatrix after = readCount.counts();
Assert.assertEquals(before.getColumnDimension(), after.getColumnDimension());
Assert.assertEquals(before.getRowDimension(), after.getRowDimension());
for (int i = 0; i < after.getColumnDimension(); i++) {
for (int j = 0; j < after.getRowDimension(); j++) {
final double beforeValue = before.getEntry(j, i);
final double afterValue = after.getEntry(j, i);
Assert.assertEquals(afterValue, beforeValue / targetFactors[j], 0.001);
}
}
}
use of org.apache.commons.math3.linear.RealMatrix in project gatk-protected by broadinstitute.
the class RamPCACoveragePoNUnitTest method assertReducedPanelCounts.
private void assertReducedPanelCounts(final PCACoveragePoN filePoN, final PCACoveragePoN ramPoN) {
final RealMatrix ramNormalizedCounts = ramPoN.getReducedPanelCounts();
final RealMatrix fileNormalizedCounts = filePoN.getReducedPanelCounts();
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.getReducedPanelCounts().getEntry(3, 4), 500000, 1e-9);
Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts).getNorm() < 1e-9);
final RealMatrix fileNormalizedCounts2 = filePoN.getReducedPanelCounts();
Assert.assertFalse(ramNormalizedCounts.subtract(fileNormalizedCounts2).getNorm() < 1e-9);
}
use of org.apache.commons.math3.linear.RealMatrix in project gatk-protected 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);
}
Aggregations