Search in sources :

Example 91 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class DataUpdaterTest method testLoadRNASeqData.

/*
     * More realistic test of RNA seq. GSE19166
     *

     */
@Test
public void testLoadRNASeqData() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGenerator());
    ExpressionExperiment ee;
    try {
        Collection<?> results = geoService.fetchAndLoad("GSE19166", false, false, false);
        ee = (ExpressionExperiment) results.iterator().next();
    } catch (AlreadyExistsInSystemException e) {
        ee = (ExpressionExperiment) ((List<?>) e.getData()).get(0);
    }
    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/GSE19166_expression_count.test.txt");
        InputStream rpkmData = this.getClass().getResourceAsStream("/data/loader/expression/flatfileload/GSE19166_expression_RPKM.test.txt")) {
        DoubleMatrix<String, String> countMatrix = reader.read(countData);
        DoubleMatrix<String, String> rpkmMatrix = reader.read(rpkmData);
        List<String> probeNames = countMatrix.getRowNames();
        assertEquals(199, probeNames.size());
        // we have to find the right generic platform to use.
        targetArrayDesign = this.getTestPersistentArrayDesign(probeNames, taxonService.findByCommonName("human"));
        targetArrayDesign = arrayDesignService.thaw(targetArrayDesign);
        assertEquals(199, targetArrayDesign.getCompositeSequences().size());
        // Main step.
        dataUpdater.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, 36, true, false);
    }
    ee = experimentService.thaw(ee);
    // should have: log2cpm, counts, rpkm, and counts-masked ('preferred')
    assertEquals(4, ee.getQuantitationTypes().size());
    for (BioAssay ba : ee.getBioAssays()) {
        assertEquals(targetArrayDesign, ba.getArrayDesignUsed());
    }
    assertNotNull(ee.getNumberOfDataVectors());
    assertEquals(199, ee.getNumberOfDataVectors().intValue());
    // GSM475204 GSM475205 GSM475206 GSM475207 GSM475208 GSM475209
    // 3949585 3929008 3712314 3693219 3574068 3579631
    ExpressionDataDoubleMatrix mat = dataMatrixService.getProcessedExpressionDataMatrix(ee);
    assertEquals(199, mat.rows());
    TestUtils.assertBAs(ee, targetArrayDesign, "GSM475204", 3949585);
    assertEquals(3 * 199, ee.getRawExpressionDataVectors().size());
    assertEquals(199, ee.getProcessedExpressionDataVectors().size());
    Collection<DoubleVectorValueObject> processedDataArrays = dataVectorService.getProcessedDataArrays(ee);
    assertEquals(199, processedDataArrays.size());
    for (DoubleVectorValueObject v : processedDataArrays) {
        assertEquals(6, v.getBioAssays().size());
    }
    assertTrue(!dataVectorService.getProcessedDataVectors(experimentService.load(ee.getId())).isEmpty());
}
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 92 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExperimentalDesignImporterTestB method testParseLoadDelete.

@Test
public final void testParseLoadDelete() throws Exception {
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/gill2007temperatureGemmaAnnotationData.txt")) {
        experimentalDesignImporter.importDesign(ee, is);
    }
    this.checkResults();
    this.aclTestUtils.checkEEAcls(ee);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    int s = ee.getExperimentalDesign().getExperimentalFactors().size();
    ExperimentalFactor toDelete = ee.getExperimentalDesign().getExperimentalFactors().iterator().next();
    experimentalFactorService.delete(toDelete);
    ee = this.expressionExperimentService.load(ee.getId());
    ee = expressionExperimentService.thawLite(ee);
    assertEquals(s - 1, ee.getExperimentalDesign().getExperimentalFactors().size());
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        for (FactorValue fv : bm.getFactorValues()) {
            assertTrue(!fv.getExperimentalFactor().equals(toDelete));
        }
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) InputStream(java.io.InputStream) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 93 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class BioAssayDimensionValueObject method makeDummyBioAssayDimension.

private BioAssayDimension makeDummyBioAssayDimension() {
    assert this.id == null;
    BioAssayDimension fakeBd = BioAssayDimension.Factory.newInstance("Placeholder representing: " + name, description, new ArrayList<BioAssay>());
    Map<Long, ExperimentalFactor> fakeEfs = new HashMap<>();
    for (BioAssayValueObject bav : this.bioAssays) {
        BioAssay ba = BioAssay.Factory.newInstance();
        ba.setId(bav.getId());
        ba.setName(bav.getName());
        ba.setDescription("Fake placeholder");
        BioMaterial sampleUsed = BioMaterial.Factory.newInstance();
        BioMaterialValueObject bmVo = bav.getSample();
        assert bmVo != null;
        sampleUsed.setId(bmVo.getId());
        sampleUsed.setName(bmVo.getName());
        sampleUsed.setDescription("Fake placeholder");
        for (IdentifiableValueObject iVo : bmVo.getFactorValueObjects()) {
            FactorValueValueObject fvVo = (FactorValueValueObject) iVo;
            FactorValue fv = FactorValue.Factory.newInstance();
            assert fvVo.getId() != null;
            fv.setId(fvVo.getId());
            assert fvVo.getValue() != null;
            fv.setValue(fvVo.getValue());
            Long efId = fvVo.getFactorId();
            ExperimentalFactor ef;
            if (fakeEfs.containsKey(efId)) {
                ef = fakeEfs.get(efId);
            } else {
                ef = ExperimentalFactor.Factory.newInstance();
                ef.setId(efId);
                ef.setName(fvVo.getCategory());
                ef.setType(fvVo.isMeasurement() ? FactorType.CONTINUOUS : FactorType.CATEGORICAL);
                fakeEfs.put(efId, ef);
            }
            ef.getFactorValues().add(fv);
            fv.setExperimentalFactor(ef);
            sampleUsed.getFactorValues().add(fv);
        }
        ba.setSampleUsed(sampleUsed);
        ArrayDesign ad = ArrayDesign.Factory.newInstance();
        ArrayDesignValueObject adVo = bav.getArrayDesign();
        assert adVo != null;
        ad.setId(adVo.getId());
        ad.setShortName(adVo.getShortName());
        ad.setDescription("Fake placeholder");
        ba.setArrayDesignUsed(ad);
        fakeBd.getBioAssays().add(ba);
    }
    return fakeBd;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) FactorValueValueObject(ubic.gemma.model.expression.experiment.FactorValueValueObject) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ArrayDesignValueObject(ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) IdentifiableValueObject(ubic.gemma.model.IdentifiableValueObject) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 94 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class BioMaterialServiceImpl method associateBatchFactor.

@Override
public void associateBatchFactor(final Map<BioMaterial, Date> dates, final Map<Date, FactorValue> d2fv) {
    for (final BioMaterial bm : dates.keySet()) {
        final BioMaterial toUpdate = this.bioMaterialDao.load(bm.getId());
        if (!d2fv.isEmpty()) {
            toUpdate.getFactorValues().add(d2fv.get(dates.get(toUpdate)));
        }
        for (final BioAssay ba : toUpdate.getBioAssaysUsedIn()) {
            if (ba.getProcessingDate() != null) {
                if (!ba.getProcessingDate().equals(dates.get(toUpdate))) {
                    ba.setProcessingDate(dates.get(toUpdate));
                    bioAssayDao.update(ba);
                }
            } else {
                ba.setProcessingDate(dates.get(toUpdate));
                bioAssayDao.update(ba);
            }
        }
        bioMaterialDao.update(toUpdate);
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 95 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionExperimentDaoImpl method thaw.

private ExpressionExperiment thaw(ExpressionExperiment ee, boolean vectorsAlso) {
    if (ee == null) {
        return null;
    }
    if (ee.getId() == null)
        throw new IllegalArgumentException("id cannot be null, cannot be thawed: " + ee);
    /*
         * Trying to do everything fails miserably, so we still need a hybrid approach. But returning the thawed object,
         * as opposed to thawing the one passed in, solves problems.
         */
    String thawQuery = "select distinct e from ExpressionExperiment e " + " left join fetch e.accession acc left join fetch acc.externalDatabase where e.id=:eeId";
    List res = this.getSessionFactory().getCurrentSession().createQuery(thawQuery).setParameter("eeId", ee.getId()).list();
    if (res.size() == 0) {
        throw new IllegalArgumentException("No experiment with id=" + ee.getId() + " could be loaded.");
    }
    ExpressionExperiment result = (ExpressionExperiment) res.iterator().next();
    Hibernate.initialize(result.getMeanVarianceRelation());
    Hibernate.initialize(result.getQuantitationTypes());
    Hibernate.initialize(result.getCharacteristics());
    Hibernate.initialize(result.getRawDataFile());
    Hibernate.initialize(result.getPrimaryPublication());
    Hibernate.initialize(result.getOtherRelevantPublications());
    Hibernate.initialize(result.getBioAssays());
    Hibernate.initialize(result.getAuditTrail());
    Hibernate.initialize(result.getGeeq());
    if (result.getAuditTrail() != null)
        Hibernate.initialize(result.getAuditTrail().getEvents());
    Hibernate.initialize(result.getCurationDetails());
    for (BioAssay ba : result.getBioAssays()) {
        Hibernate.initialize(ba.getArrayDesignUsed());
        Hibernate.initialize(ba.getArrayDesignUsed().getDesignProvider());
        Hibernate.initialize(ba.getDerivedDataFiles());
        Hibernate.initialize(ba.getSampleUsed());
        BioMaterial bm = ba.getSampleUsed();
        if (bm != null) {
            Hibernate.initialize(bm.getFactorValues());
            Hibernate.initialize(bm.getTreatments());
        }
    }
    ExperimentalDesign experimentalDesign = result.getExperimentalDesign();
    if (experimentalDesign != null) {
        Hibernate.initialize(experimentalDesign);
        Hibernate.initialize(experimentalDesign.getExperimentalFactors());
        experimentalDesign.getTypes().size();
        for (ExperimentalFactor factor : experimentalDesign.getExperimentalFactors()) {
            Hibernate.initialize(factor.getAnnotations());
            for (FactorValue f : factor.getFactorValues()) {
                Hibernate.initialize(f.getCharacteristics());
                if (f.getMeasurement() != null) {
                    Hibernate.initialize(f.getMeasurement());
                    if (f.getMeasurement().getUnit() != null) {
                        Hibernate.initialize(f.getMeasurement().getUnit());
                    }
                }
            }
        }
    }
    this.thawReferences(result);
    this.thawMeanVariance(result);
    if (vectorsAlso) {
        /*
             * Optional because this could be slow.
             */
        Hibernate.initialize(result.getRawExpressionDataVectors());
        Hibernate.initialize(result.getProcessedExpressionDataVectors());
    }
    return result;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)144 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)67 Test (org.junit.Test)29 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)29 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)20 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)15 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)14 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)14 InputStream (java.io.InputStream)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)10 HashSet (java.util.HashSet)9 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)8 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)8 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)7