Search in sources :

Example 1 with ExpressionDataSVD

use of ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD in project Gemma by PavlidisLab.

the class ExpressionDataSVDTest method testUMatrixAsExpressionData.

@Test
public void testUMatrixAsExpressionData() {
    svd = new ExpressionDataSVD(testData, true);
    ExpressionDataDoubleMatrix matrixAsExpressionData = svd.uMatrixAsExpressionData();
    assertNotNull(matrixAsExpressionData);
}
Also used : ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) ExpressionDataSVD(ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD) Test(org.junit.Test)

Example 2 with ExpressionDataSVD

use of ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD in project Gemma by PavlidisLab.

the class ExpressionDataSVDTest method setUp.

@Before
public void setUp() throws Exception {
    testData = new ExpressionDataTestMatrix();
    svd = new ExpressionDataSVD(testData, false);
}
Also used : ExpressionDataTestMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataTestMatrix) ExpressionDataSVD(ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD) Before(org.junit.Before)

Example 3 with ExpressionDataSVD

use of ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD in project Gemma by PavlidisLab.

the class ExpressionDataSVDTest method testEigenvalues.

/*
     * <pre>
     * testdata<-read.table("C:/users/paul/dev/eclipseworkspace/Gemma/gemma-core/src/test/resources/data/loader/aov.results-2-monocyte-data-bytime.bypat.data.sort",
     *          header=T, row.names=1)
     * testdata.s <- testdata
     * for(i in 1:5) {
     *   testdata.s <-  t(scale(t(scale(testdata.s))));  
     * }
     * s<-svd(testdata.s)
     * s$d
     * # eigens:
     * s$d^2/ (nrow(testdata.s) - 1)
     * # or
     * p<-prcomp(testdata.s, center=F, scale=F)
     * p$sdev^2
     * # or
     * eigen(cov(testdata.s), only.values = TRUE)
     * </pre>
     */
@Test
public void testEigenvalues() {
    svd = new ExpressionDataSVD(testData, true);
    double[] singularValues = svd.getSingularValues();
    double[] expectedSingularValues = new double[] { 44.33292, 41.91284, 40.28428, 31.91613, 25.80453, 23.97011, 20.62388, 20.02206, 17.71859, 16.61712, 16.19350, 14.76118, 13.87069, 13.10054, 12.54802, 11.52781, 11.11996, 10.36422, 10.09994, 9.691179, 9.153403, 8.634105, 7.881425, 7.754466, 7.245502, 6.993059, 6.832636, 6.797229, 6.250005, 6.155713, 6.007695, 5.841762, 5.530337, 5.307789, 5.175314, 5.135153, 4.951609, 4.775425, 4.68693, 4.447738, 4.302409, 4.195906, 3.964473, 3.808823, 3.75757, 3.701613, 3.558042, 3.48766, 3.337000, 3.274710, 3.079108, 3.023564, 2.837062, 2.690218, 2.582036, 2.351277, 2.171346, 1.877483, 2.745043e-15 };
    assertEquals(59, singularValues.length);
    assertTrue(RegressionTesting.closeEnough(expectedSingularValues, singularValues, 0.05));
    double[] eigenvalues = svd.getEigenvalues();
    double[] actualEigenValues = new double[] { 9.876418, 8.827503, 8.154231, 5.118728, 3.346094, 2.887258, 2.13741, 2.014482, 1.577620, 1.387581, 1.317728, 1.094936, 0.9668133, 0.8624328, 0.7912195, 0.667791, 0.621372, 0.5397819, 0.5126067, 0.4719545, 0.4210288, 0.3746118, 0.3121450, 0.3021694, 0.2638054, 0.2457431, 0.2345975, 0.2321725, 0.1962941, 0.1904161, 0.1813688, 0.1714884, 0.1536916, 0.1415709, 0.1345923, 0.1325116, 0.1232082, 0.1145964, 0.1103885, 0.09940891, 0.09301872, 0.08847049, 0.0789801, 0.07290015, 0.07095141, 0.06885395, 0.0636164, 0.06112447, 0.05595763, 0.05388808, 0.04764272, 0.04593939, 0.04044683, 0.03636818, 0.03350205, 0.02778140, 0.02369217, 0.01771328, 2.365972e-16 };
    assertEquals(59, eigenvalues.length);
    assertTrue(RegressionTesting.closeEnough(actualEigenValues, eigenvalues, 0.01));
}
Also used : ExpressionDataSVD(ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD) Test(org.junit.Test)

Example 4 with ExpressionDataSVD

use of ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD in project Gemma by PavlidisLab.

the class LinkAnalysisServiceImpl method normalize.

/**
 * Normalize the data, as configured (possibly no normalization).
 */
private ExpressionDataDoubleMatrix normalize(ExpressionDataDoubleMatrix datamatrix, LinkAnalysisConfig config) {
    ExpressionDataSVD svd;
    switch(config.getNormalizationMethod()) {
        case none:
            return datamatrix;
        case SVD:
            LinkAnalysisServiceImpl.log.info("SVD normalizing");
            svd = new ExpressionDataSVD(datamatrix, true);
            return svd.removeHighestComponents(1);
        case SPELL:
            LinkAnalysisServiceImpl.log.info("Computing U matrix via SVD");
            svd = new ExpressionDataSVD(datamatrix, true);
            return svd.uMatrixAsExpressionData();
        case BALANCE:
            LinkAnalysisServiceImpl.log.info("SVD-balanceing");
            svd = new ExpressionDataSVD(datamatrix, true);
            return svd.equalize();
        default:
            return null;
    }
}
Also used : ExpressionDataSVD(ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD)

Example 5 with ExpressionDataSVD

use of ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD in project Gemma by PavlidisLab.

the class ExpressionDataSVDTest method testMatrixReconstructB.

/*
     * Test on full-sized data set.
     */
@Test
public void testMatrixReconstructB() throws Exception {
    GeoConverter gc = new GeoConverterImpl();
    InputStream is = new GZIPInputStream(this.getClass().getResourceAsStream("/data/loader/expression/geo/fullSizeTests/GSE1623_family.soft.txt.gz"));
    GeoFamilyParser parser = new GeoFamilyParser();
    parser.parse(is);
    GeoSeries series = ((GeoParseResult) parser.getResults().iterator().next()).getSeriesMap().get("GSE1623");
    DatasetCombiner datasetCombiner = new DatasetCombiner();
    GeoSampleCorrespondence correspondence = datasetCombiner.findGSECorrespondence(series);
    series.setSampleCorrespondence(correspondence);
    @SuppressWarnings("unchecked") Collection<ExpressionExperiment> result = (Collection<ExpressionExperiment>) gc.convert(series);
    assertNotNull(result);
    assertEquals(1, result.size());
    ExpressionExperiment ee = result.iterator().next();
    ExpressionDataDoubleMatrix matrix = new ExpressionDataDoubleMatrix(ee.getRawExpressionDataVectors(), ee.getQuantitationTypes().iterator().next());
    svd = new ExpressionDataSVD(matrix, false);
    ExpressionDataDoubleMatrix svdNormalize = svd.removeHighestComponents(1);
    assertNotNull(svdNormalize);
}
Also used : GeoSeries(ubic.gemma.core.loader.expression.geo.model.GeoSeries) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) ExpressionDataSVD(ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD) GZIPInputStream(java.util.zip.GZIPInputStream) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

ExpressionDataSVD (ubic.gemma.core.analysis.preprocess.svd.ExpressionDataSVD)5 Test (org.junit.Test)3 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Before (org.junit.Before)1 ExpressionDataTestMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataTestMatrix)1 GeoSeries (ubic.gemma.core.loader.expression.geo.model.GeoSeries)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1