Search in sources :

Example 26 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class TwoWayAnovaWithInteractionsTest2 method setup.

@Before
public void setup() throws Exception {
    geoService.setGeoDomainObjectGenerator(new GeoDomainObjectGeneratorLocal(FileTools.resourceToPath("/data/analysis/expression/gse18795short")));
    try {
        Collection<?> results = geoService.fetchAndLoad("GSE18795", 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/gse18795short/6290_GSE18795_expdesign.data.txt"));
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) Collection(java.util.Collection) AlreadyExistsInSystemException(ubic.gemma.core.loader.util.AlreadyExistsInSystemException) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GeoDomainObjectGeneratorLocal(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal) HashSet(java.util.HashSet) Before(org.junit.Before)

Example 27 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class FactorValueVector method buildKey.

private String buildKey() {
    StringBuilder buf = new StringBuilder();
    buf.append("[");
    for (Iterator<ExperimentalFactor> i = factors.iterator(); i.hasNext(); ) {
        ExperimentalFactor factor = i.next();
        buf.append(factor.getCategory());
        buf.append(factor.getName()).append(" (").append(factor.getDescription()).append(")");
        buf.append(" => [ ");
        for (Iterator<FactorValue> it = this.getValuesForFactor(factor).iterator(); it.hasNext(); ) {
            buf.append(it.next());
            if (it.hasNext())
                buf.append(", ");
        }
        buf.append(" ] ");
        if (i.hasNext())
            buf.append("; ");
    }
    buf.append("]");
    return buf.toString();
}
Also used : FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor)

Example 28 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class ContinuousVariableDiffExTest method test.

@Test
public void test() {
    AnalysisType aa = analysisService.determineAnalysis(ee, ee.getExperimentalDesign().getExperimentalFactors(), null, true);
    assertEquals(AnalysisType.GENERICLM, aa);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    assertEquals(1, factors.size());
    config.setAnalysisType(aa);
    config.setFactorsToInclude(factors);
    analyzer = this.getBean(DiffExAnalyzer.class);
    Collection<DifferentialExpressionAnalysis> result = analyzer.run(ee, config);
    assertEquals(1, result.size());
    DifferentialExpressionAnalysis analysis = result.iterator().next();
    assertNotNull(analysis);
    Map<ExperimentalFactor, FactorValue> baselineLevels = ExpressionDataMatrixColumnSort.getBaselineLevels(ee.getExperimentalDesign().getExperimentalFactors());
    assertEquals(1, baselineLevels.size());
    FactorValue fv = baselineLevels.values().iterator().next();
    assertEquals(24.0, Double.parseDouble(fv.getMeasurement().getValue()), 0.0001);
// checkResults( analysis );
}
Also used : AnalysisType(ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 29 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class ExpressionDataMatrixColumnSortTest method testOrderByExperimentalDesignB.

@Test
public void testOrderByExperimentalDesignB() {
    BioAssayDimension bad = BioAssayDimension.Factory.newInstance();
    /*
         * Five factors. Factor4 is a measurmeent.
         */
    Collection<ExperimentalFactor> factors = new HashSet<>();
    for (int i = 0; i < 5; i++) {
        ExperimentalFactor ef = ExperimentalFactor.Factory.newInstance();
        ef.setType(FactorType.CATEGORICAL);
        ef.setName("factor" + i);
        if (i == 4) {
            ef.setName("mfact" + i);
        }
        ef.setId((long) i);
        for (int j = 0; j < 3; j++) {
            FactorValue fv = FactorValue.Factory.newInstance();
            fv.setValue("fv" + (j + 1) * (i + 1));
            fv.setId((long) (j + 1) * (i + 1));
            fv.setExperimentalFactor(ef);
            ef.getFactorValues().add(fv);
            if (j == 2 && i != 4) {
                fv.setValue("control_group");
            }
            if (i == 4) {
                ef.setType(FactorType.CONTINUOUS);
                Measurement m = Measurement.Factory.newInstance();
                m.setId((long) j * (i + 1));
                m.setValue(j + ".00");
                m.setRepresentation(PrimitiveType.DOUBLE);
                fv.setMeasurement(m);
            }
        }
        factors.add(ef);
    }
    Random random = new Random();
    for (int i = 0; i < 100; i++) {
        BioAssay ba = BioAssay.Factory.newInstance();
        ba.setName("ba" + i);
        ba.setId((long) i);
        bad.getBioAssays().add(ba);
        BioMaterial bm = BioMaterial.Factory.newInstance();
        bm.setId((long) i);
        bm.setName("bm" + i);
        ba.setSampleUsed(bm);
        for (ExperimentalFactor ef : factors) {
            /*
                 * Note: if we use 4, then some of the biomaterials will not have a factorvalue for each factor. This is
                 * realistic. Use 3 to fill it in completely.
                 */
            int k = random.nextInt(4);
            int m = 0;
            FactorValue toUse = null;
            for (FactorValue fv : ef.getFactorValues()) {
                if (m == k) {
                    toUse = fv;
                    break;
                }
                m++;
            }
            if (toUse != null)
                bm.getFactorValues().add(toUse);
        // log.info( ba + " -> " + bm + " -> " + ef + " -> " + toUse );
        }
    }
    EmptyExpressionMatrix mat = new EmptyExpressionMatrix(bad);
    assertEquals(100, mat.columns());
    List<BioMaterial> ordered = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(mat);
    assertEquals(100, ordered.size());
// for ( BioMaterial bioMaterial : ordered ) {
// log.info( bioMaterial + " .... " + StringUtils.join( bioMaterial.getFactorValues(), "  --- " ) );
// }
}
Also used : Measurement(ubic.gemma.model.common.measurement.Measurement) BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) FactorValue(ubic.gemma.model.expression.experiment.FactorValue) Random(java.util.Random) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) HashSet(java.util.HashSet) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 30 with ExperimentalFactor

use of ubic.gemma.model.expression.experiment.ExperimentalFactor in project Gemma by PavlidisLab.

the class ExperimentalDesignUtils method sampleInfoMatrix.

/**
 * @return Experimental design matrix
 */
public static ObjectMatrix<BioMaterial, ExperimentalFactor, Object> sampleInfoMatrix(List<ExperimentalFactor> factors, List<BioMaterial> samplesUsed, Map<ExperimentalFactor, FactorValue> baselines) {
    ObjectMatrix<BioMaterial, ExperimentalFactor, Object> designMatrix = new ObjectMatrixImpl<>(samplesUsed.size(), factors.size());
    designMatrix.setColumnNames(factors);
    int row = 0;
    for (BioMaterial samp : samplesUsed) {
        int col = 0;
        for (ExperimentalFactor factor : factors) {
            Object value = ExperimentalDesignUtils.extractFactorValueForSample(baselines, samp, factor);
            designMatrix.set(row, col, value);
            col++;
        }
        row++;
    }
    designMatrix.setRowNames(samplesUsed);
    return designMatrix;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) ExperimentalFactorValueObject(ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject) ObjectMatrixImpl(ubic.basecode.dataStructure.matrix.ObjectMatrixImpl)

Aggregations

ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)88 Test (org.junit.Test)31 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)26 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)22 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18 HashSet (java.util.HashSet)17 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)17 ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)16 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)14 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)12 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)11 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)10 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)10 Before (org.junit.Before)8 Collection (java.util.Collection)7 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)6 AnalysisType (ubic.gemma.core.analysis.expression.diff.DifferentialExpressionAnalyzerServiceImpl.AnalysisType)5 ExperimentalFactorValueObject (ubic.gemma.model.expression.experiment.ExperimentalFactorValueObject)5 InputStream (java.io.InputStream)4