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());
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations