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