use of ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorServiceTest method getDataset.
private Collection<ExpressionExperiment> getDataset() throws Exception {
// Dataset uses spotted arrays, 11 samples.
ExpressionExperiment ee;
try {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gse432Short")));
// noinspection unchecked
Collection<ExpressionExperiment> results = (Collection<ExpressionExperiment>) geoService.fetchAndLoad("GSE432", false, true, false);
ee = results.iterator().next();
TwoChannelMissingValues tcmv = this.getBean(TwoChannelMissingValues.class);
tcmv.computeMissingValues(ee, 1.5, null);
// No masked preferred computation.
} catch (AlreadyExistsInSystemException e) {
if (e.getData() instanceof List) {
ee = (ExpressionExperiment) ((List<?>) e.getData()).iterator().next();
} else {
ee = (ExpressionExperiment) e.getData();
}
} catch (Exception e) {
if (e.getCause() instanceof IOException && e.getCause().getMessage().contains("502")) {
return null;
}
throw e;
}
ee.setShortName(RandomStringUtils.randomAlphabetic(12));
expressionExperimentService.update(ee);
ee = expressionExperimentService.thawLite(ee);
processedDataVectorService.createProcessedDataVectors(ee);
Collection<ExpressionExperiment> e = new HashSet<>();
e.add(ee);
return e;
}
use of ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal in project Gemma by PavlidisLab.
the class SubsettedAnalysis3Test method setup.
@Before
public void setup() throws Exception {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(FileTools.resourceToPath("/data/analysis/expression/gse26927short")));
try {
Collection<?> results = geoService.fetchAndLoad("GSE26927", false, true, false);
ee = (ExpressionExperiment) results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
ee = (ExpressionExperiment) ((Collection<?>) e.getData()).iterator().next();
}
ee = expressionExperimentService.thawLite(ee);
Collection<ExperimentalFactor> toremove = new HashSet<>(ee.getExperimentalDesign().getExperimentalFactors());
for (ExperimentalFactor ef : toremove) {
experimentalFactorService.delete(ef);
ee.getExperimentalDesign().getExperimentalFactors().remove(ef);
}
expressionExperimentService.update(ee);
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
ee = expressionExperimentService.thaw(ee);
designImporter.importDesign(ee, this.getClass().getResourceAsStream("/data/analysis/expression/gse26927short/2684_GSE26927_expdesign.data.txt"));
}
use of ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal in project Gemma by PavlidisLab.
the class MeanVarianceServiceTest method setUp.
@Before
public void setUp() throws Exception {
ee = eeService.findByShortName("GSE2982");
if (ee != null) {
// might work, but array designs might be in the way.
eeService.remove(ee);
}
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gse2982Short")));
Collection<?> results = geoService.fetchAndLoad("GSE2982", false, false, false);
ee = (ExpressionExperiment) results.iterator().next();
qt = this.createOrUpdateQt(ScaleType.LINEAR);
qt.setIsNormalized(true);
quantitationTypeService.update(qt);
// important bit, need to createProcessedVectors manually before using it
ee = processedExpressionDataVectorService.createProcessedDataVectors(ee);
}
use of ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal in project Gemma by PavlidisLab.
the class ProcessedExpressionDataCreateServiceTest method testReorder.
@Test
public void testReorder() throws Exception {
ExpressionExperiment old = eeService.findByShortName("GSE404");
if (old != null) {
eeService.remove(old);
}
try {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gse404Short")));
@SuppressWarnings("unchecked") Collection<ExpressionExperiment> results = (Collection<ExpressionExperiment>) geoService.fetchAndLoad("GSE404", false, true, false);
this.ee = results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
this.ee = (ExpressionExperiment) e.getData();
}
ee = this.eeService.thawLite(ee);
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
ExperimentalFactor factor = ExperimentalFactor.Factory.newInstance();
factor.setType(FactorType.CATEGORICAL);
factor.setName(ee.getShortName() + " design");
factor.setExperimentalDesign(ee.getExperimentalDesign());
factor = eeService.addFactor(ee, factor);
FactorValue fv1 = FactorValue.Factory.newInstance();
FactorValue fv2 = FactorValue.Factory.newInstance();
fv1.setValue("foo");
fv1.setExperimentalFactor(factor);
fv2.setValue("bar");
fv2.setIsBaseline(true);
fv2.setExperimentalFactor(factor);
eeService.addFactorValue(ee, fv1);
eeService.addFactorValue(ee, fv2);
List<BioAssay> basInOrder = new ArrayList<>(ee.getBioAssays());
Collections.sort(basInOrder, new Comparator<BioAssay>() {
@Override
public int compare(BioAssay o1, BioAssay o2) {
return o1.getId().compareTo(o2.getId());
}
});
int i = 0;
for (BioAssay ba : basInOrder) {
// bioAssayService.thawRawAndProcessed( ba );
BioMaterial bm = ba.getSampleUsed();
assert fv1.getId() != null;
if (!bm.getFactorValues().isEmpty()) {
continue;
}
if (i % 2 == 0) {
bm.getFactorValues().add(fv1);
// log.info( bm + " " + bm.getId() + " => " + fv1 );
} else {
bm.getFactorValues().add(fv2);
// log.info( bm + " " + bm.getId() + " => " + fv2 );
}
bioMaterialService.update(bm);
i++;
}
factor = this.experimentalFactorService.load(factor.getId());
assertEquals(2, factor.getFactorValues().size());
/*
* All that was setup. Now do the interesting bit
*/
processedExpressionDataVectorService.reorderByDesign(ee.getId());
/*
* Now check the vectors...
*/
Collection<ProcessedExpressionDataVector> resortedVectors = processedExpressionDataVectorService.getProcessedDataVectors(ee);
// ExpressionDataDoubleMatrix newMat = new ExpressionDataDoubleMatrix( resortedVectors );
// log.info( newMat );
boolean foundVector = false;
assertTrue(resortedVectors.size() > 0);
for (ProcessedExpressionDataVector vector : resortedVectors) {
i = 0;
log.debug(vector.getDesignElement().getName() + " .........................");
// thawingto avoid lazy error because we are outside of transaction in this test. All references in code run
// inside a transaction
BioAssayDimension bioAssayDimension = vector.getBioAssayDimension();
bioAssayDimensionService.thawLite(bioAssayDimension);
Collection<BioAssay> bioAssays = bioAssayDimension.getBioAssays();
for (BioAssay ba : bioAssays) {
BioMaterial bm = ba.getSampleUsed();
assertEquals(1, bm.getFactorValues().size());
FactorValue fv = bm.getFactorValues().iterator().next();
assertNotNull(fv.getId());
log.debug(ba.getId() + " " + fv.getId() + " " + fv);
if (i < 10) {
// first because it is baseline;
assertEquals(fv2, fv);
}
i++;
}
/*
* spot check the data, same place as before.
*/
if (vector.getDesignElement().getName().equals("40")) {
foundVector = true;
ByteArrayConverter conv = new ByteArrayConverter();
Double[] d = ArrayUtils.toObject(conv.byteArrayToDoubles(vector.getData()));
assertEquals(20, d.length);
assertEquals(-0.08, d[1], 0.001);
assertEquals(0.45, d[10], 0.001);
assertEquals(Double.NaN, d[19], 0.001);
}
}
assertTrue("test vector not found", foundVector);
}
use of ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal in project Gemma by PavlidisLab.
the class ProcessedExpressionDataCreateServiceTest method testComputeDevRankForExpressionExperimentMultiArrayWithGaps.
/**
* Three platforms, one sample was not run on GPL81. It's 'Norm-1a', but the name we use for the sample is random.
*/
@SuppressWarnings("unchecked")
@Test
public void testComputeDevRankForExpressionExperimentMultiArrayWithGaps() throws Exception {
try {
geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(this.getTestFileBasePath("gse482short")));
Collection<ExpressionExperiment> results = (Collection<ExpressionExperiment>) geoService.fetchAndLoad("GSE482", false, true, false);
this.ee = results.iterator().next();
} catch (AlreadyExistsInSystemException e) {
this.ee = ((Collection<ExpressionExperiment>) e.getData()).iterator().next();
}
ee = this.eeService.thawLite(ee);
processedExpressionDataVectorService.computeProcessedExpressionData(ee);
Collection<ProcessedExpressionDataVector> preferredVectors = this.processedExpressionDataVectorService.getProcessedDataVectors(ee);
ee = eeService.load(ee.getId());
ee = this.eeService.thawLite(ee);
processedExpressionDataVectorService.thaw(preferredVectors);
ExpressionDataDoubleMatrix mat = new ExpressionDataDoubleMatrix(preferredVectors);
assertEquals(10, mat.columns());
boolean found = false;
for (int i = 0; i < mat.rows(); i++) {
Double[] row = mat.getRow(i);
// debugging
if (i == 0) {
for (int j = 0; j < row.length; j++) {
BioAssay ba = mat.getBioAssaysForColumn(j).iterator().next();
System.err.println(ba.getName());
}
}
System.err.print(mat.getRowElement(i).getDesignElement().getName() + "\t");
for (double d : row) {
System.err.print(String.format("%4.2f\t", d));
}
System.err.print("\n");
CompositeSequence el = mat.getDesignElementForRow(i);
for (int j = 0; j < row.length; j++) {
BioAssay ba = mat.getBioAssaysForColumn(j).iterator().next();
if (ba.getName().matches("PGA-MurLungHyper-Norm-1a[ABC]v2-s2") && (el.getName().equals("100001_at") || el.getName().equals("100002_at") || el.getName().equals("100003_at") || el.getName().equals("100004_at") || el.getName().equals("100005_at") || el.getName().equals("100006_at") || el.getName().equals("100007_at") || el.getName().equals("100009_r_at") || el.getName().equals("100010_at") || el.getName().equals("100011_at"))) {
assertEquals(Double.NaN, row[j], 0.0001);
found = true;
} else {
assertTrue("Got unexpected NA value for " + ba.getName() + " for " + el.getName(), !Double.isNaN(row[j]));
}
}
}
assertTrue(found);
/*
* Now do this through the processedExpressionDataVectorService
*/
Collection<DoubleVectorValueObject> da = this.processedExpressionDataVectorService.getProcessedDataArrays(ee);
assertEquals(30, da.size());
found = false;
boolean first = true;
for (DoubleVectorValueObject v : da) {
CompositeSequenceValueObject el = v.getDesignElement();
double[] row = v.getData();
// debugging
if (first) {
for (int j = 0; j < row.length; j++) {
BioAssayValueObject ba = v.getBioAssays().get(j);
System.err.println(ba.getName());
}
first = false;
}
System.err.print(el.getName() + "\t");
for (double d : row) {
System.err.print(String.format("%4.2f\t", d));
}
System.err.print("\n");
assertEquals(10, row.length);
for (int j = 0; j < row.length; j++) {
assertNotNull(v.getBioAssays());
BioAssayValueObject ba = v.getBioAssays().get(j);
if (ba.getName().startsWith("Missing bioassay for biomaterial") && (el.getName().equals("100001_at") || el.getName().equals("100002_at") || el.getName().equals("100003_at") || el.getName().equals("100004_at") || el.getName().equals("100005_at") || el.getName().equals("100006_at") || el.getName().equals("100007_at") || el.getName().equals("100009_r_at") || el.getName().equals("100010_at") || el.getName().equals("100011_at"))) {
assertEquals(Double.NaN, row[j], 0.0001);
found = true;
} else {
assertTrue("Got unexpected NA value for " + ba.getName() + " for " + el.getName(), !Double.isNaN(row[j]));
}
}
}
assertTrue(found);
}
Aggregations