Search in sources :

Example 1 with DoubleMatrixReader

use of ubic.basecode.io.reader.DoubleMatrixReader in project Gemma by PavlidisLab.

the class DataUpdaterTest method testLoadRNASeqDataWithMissingSamples.

/*
     * Test case where some samples cannot be used.
     *
     */
@Test
public void testLoadRNASeqDataWithMissingSamples() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator());
    ExpressionExperiment ee = experimentService.findByShortName("GSE29006");
    if (ee != null) {
        experimentService.remove(ee);
    }
    assertTrue(experimentService.findByShortName("GSE29006") == null);
    try {
        Collection<?> results = geoService.fetchAndLoad("GSE29006", false, false, false);
        ee = (ExpressionExperiment) results.iterator().next();
    } catch (AlreadyExistsInSystemException e) {
        throw new IllegalStateException("Need to remove this data set before test is run");
    }
    ee = experimentService.thaw(ee);
    // Load the data from a text file.
    DoubleMatrixReader reader = new DoubleMatrixReader();
    try (InputStream countData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_expression_count.test.txt");
        InputStream rpkmData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE29006_expression_RPKM.test.txt")) {
        DoubleMatrix<String, String> countMatrix = reader.read(countData);
        DoubleMatrix<String, String> rpkmMatrix = reader.read(rpkmData);
        List<String> probeNames = countMatrix.getRowNames();
        // we have to find the right generic platform to use.
        targetArrayDesign = this.getTestPersistentArrayDesign(probeNames, taxonService.findByCommonName("human"));
        targetArrayDesign = arrayDesignService.thaw(targetArrayDesign);
        try {
            dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, 36, true, false);
            fail("Should have gotten an exception");
        } catch (IllegalArgumentException e) {
        // Expected
        }
        dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, 36, true, true);
    }
    /*
         * Check
         */
    ee = experimentService.thaw(ee);
    for (BioAssay ba : ee.getBioAssays()) {
        assertEquals(targetArrayDesign, ba.getArrayDesignUsed());
    }
    ExpressionDataDoubleMatrix mat = dataMatrixService.getProcessedExpressionDataMatrix(ee);
    assertEquals(199, mat.rows());
    assertTrue(mat.getQuantitationTypes().iterator().next().getName().startsWith("log2cpm"));
    assertEquals(4, ee.getBioAssays().size());
    assertEquals(199 * 3, ee.getRawExpressionDataVectors().size());
    assertEquals(199, ee.getProcessedExpressionDataVectors().size());
    Collection<DoubleVectorValueObject> processedDataArrays = dataVectorService.getProcessedDataArrays(ee);
    assertEquals(199, processedDataArrays.size());
    TestUtils.assertBAs(ee, targetArrayDesign, "GSM718709", 320383);
    for (DoubleVectorValueObject v : processedDataArrays) {
        assertEquals(4, v.getBioAssays().size());
    }
}
Also used : InputStream(java.io.InputStream) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) GeoDomainObjectGenerator(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator) AlreadyExistsInSystemException(ubic.gemma.core.loader.util.AlreadyExistsInSystemException) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 2 with DoubleMatrixReader

use of ubic.basecode.io.reader.DoubleMatrixReader in project Gemma by PavlidisLab.

the class ComBatTest method test5NonParametric.

@Test
public void test5NonParametric() throws Exception {
    DoubleMatrixReader f = new DoubleMatrixReader();
    DoubleMatrix<String, String> testMatrix = f.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/GSE492.test.dat.txt"));
    StringMatrixReader of = new StringMatrixReader();
    StringMatrix<String, String> sampleInfo = of.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/100_GSE492_expdesign.data.txt"));
    @SuppressWarnings({ "unchecked", "rawtypes" }) ComBat<String, String> comBat = new ComBat(testMatrix, sampleInfo);
    DoubleMatrix2D X = comBat.getDesignMatrix();
    // log.info( X );
    assertEquals(1, X.get(0, 0), 0.001);
    assertEquals(0, X.get(1, 0), 0.001);
    assertEquals(0, X.get(4, 3), 0.001);
    DoubleMatrix2D y = new DenseDoubleMatrix2D(testMatrix.asArray());
    DoubleMatrix2D sdata = comBat.standardize(y, X);
    // log.info( sdata.viewPart( 0, 0, 10, 12 ) );
    assertEquals(-1.85175902, sdata.get(7, 1), 0.0001);
    assertEquals(0.2479669, sdata.get(8, 2), 0.001);
    assertEquals(-0.56259384, sdata.get(0, 8), 0.001);
    assertEquals(1.07168246, sdata.get(3, 11), 0.001);
    DoubleMatrix2D finalResult = comBat.run(false);
    assertEquals(12.026930, finalResult.get(7, 0), 0.001);
    assertEquals(11.635157, finalResult.get(7, 7), 0.01);
    assertEquals(12.930425, finalResult.get(9, 7), 0.01);
}
Also used : StringMatrixReader(ubic.basecode.io.reader.StringMatrixReader) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) Test(org.junit.Test)

Example 3 with DoubleMatrixReader

use of ubic.basecode.io.reader.DoubleMatrixReader in project Gemma by PavlidisLab.

the class ComBatTest method test3.

/**
 * Based on GSE13712
 */
@Test
public final void test3() throws Exception {
    DoubleMatrixReader f = new DoubleMatrixReader();
    DoubleMatrix<String, String> testMatrix = f.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/comat.test.data.txt"));
    StringMatrixReader of = new StringMatrixReader();
    StringMatrix<String, String> sampleInfo = of.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/combat.test.design.txt"));
    @SuppressWarnings({ "unchecked", "rawtypes" }) ComBat<String, String> comBat = new ComBat(testMatrix, sampleInfo);
    DoubleMatrix2D result = comBat.run();
    assertNotNull(result);
}
Also used : StringMatrixReader(ubic.basecode.io.reader.StringMatrixReader) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) Test(org.junit.Test)

Example 4 with DoubleMatrixReader

use of ubic.basecode.io.reader.DoubleMatrixReader in project Gemma by PavlidisLab.

the class ComBatTest method test4.

@Test
public void test4() throws Exception {
    DoubleMatrixReader f = new DoubleMatrixReader();
    DoubleMatrix<String, String> testMatrix = f.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/GSE492.test.dat.txt"));
    StringMatrixReader of = new StringMatrixReader();
    ObjectMatrix<String, String, String> sampleInfo = of.read(this.getClass().getResourceAsStream("/data/analysis/preprocess/batcheffects/100_GSE492_expdesign.data.txt"));
    @SuppressWarnings({ "unchecked", "rawtypes" }) ComBat<String, String> comBat = new ComBat(testMatrix, sampleInfo);
    DoubleMatrix2D X = comBat.getDesignMatrix();
    // log.info( X );
    assertEquals(1, X.get(0, 0), 0.001);
    assertEquals(0, X.get(1, 0), 0.001);
    assertEquals(0, X.get(4, 3), 0.001);
    DoubleMatrix2D y = new DenseDoubleMatrix2D(testMatrix.asArray());
    DoubleMatrix2D sdata = comBat.standardize(y, X);
    // log.info( sdata.viewPart( 0, 0, 10, 12 ) );
    assertEquals(-1.85175902, sdata.get(7, 1), 0.0001);
    assertEquals(0.2479669, sdata.get(8, 2), 0.001);
    assertEquals(-0.56259384, sdata.get(0, 8), 0.001);
    assertEquals(1.07168246, sdata.get(3, 11), 0.001);
    DoubleMatrix2D finalResult = comBat.run();
    assertEquals(12.026468, finalResult.get(7, 0), 0.0001);
    assertEquals(11.640057, finalResult.get(7, 7), 0.0001);
    assertEquals(12.932352, finalResult.get(9, 7), 0.0001);
}
Also used : StringMatrixReader(ubic.basecode.io.reader.StringMatrixReader) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) Test(org.junit.Test)

Example 5 with DoubleMatrixReader

use of ubic.basecode.io.reader.DoubleMatrixReader in project Gemma by PavlidisLab.

the class BaseAnalyzerConfigurationTest method configureVectors.

void configureVectors(List<BioMaterial> bioMaterials, String resourcePath) throws Exception {
    this.vectors = new HashSet<>();
    DoubleMatrixReader r = new DoubleMatrixReader();
    String path;
    if (resourcePath == null) {
        path = "/data/stat-tests/anova-test-data.txt";
    } else {
        path = resourcePath;
    }
    DoubleMatrix<String, String> dataMatrix = r.read(this.getClass().getResourceAsStream(path));
    // RandomData randomData = new RandomDataImpl( new MersenneTwister( 0 ) ); // fixed seed - important!
    Collection<CompositeSequence> compositeSequences = new HashSet<>();
    for (int i = 0; i < BaseAnalyzerConfigurationTest.NUM_DESIGN_ELEMENTS; i++) {
        ProcessedExpressionDataVector vector = ProcessedExpressionDataVector.Factory.newInstance();
        vector.setBioAssayDimension(bioAssayDimension);
        vector.setQuantitationType(quantitationType);
        CompositeSequence cs = CompositeSequence.Factory.newInstance();
        cs.setName(dataMatrix.getRowName(i));
        cs.setId(i + 1000L);
        cs.setArrayDesign(arrayDesign);
        vector.setDesignElement(cs);
        vector.setId(i + 10000L);
        double[] dvals = new double[bioMaterials.size()];
        for (int j = 0; j < dvals.length; j++) {
            dvals[j] = dataMatrix.get(i, j);
        }
        byte[] bvals = bac.doubleArrayToBytes(dvals);
        vector.setData(bvals);
        vectors.add(vector);
        compositeSequences.add(cs);
    }
    expressionExperiment.setProcessedExpressionDataVectors(vectors);
    arrayDesign.setCompositeSequences(compositeSequences);
}
Also used : ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader) HashSet(java.util.HashSet)

Aggregations

DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)15 Test (org.junit.Test)11 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)6 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)6 StringMatrixReader (ubic.basecode.io.reader.StringMatrixReader)6 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)5 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)5 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)5 InputStream (java.io.InputStream)4 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)4 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)4 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)3 IOException (java.io.IOException)2 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)2 DataUpdater (ubic.gemma.core.loader.expression.geo.DataUpdater)2 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)2 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)2 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)2 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)2