use of ubic.gemma.model.expression.experiment.FactorValue 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.FactorValue 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.FactorValue in project Gemma by PavlidisLab.
the class ExperimentalDesignUtils method getBaselineConditions.
public static Map<ExperimentalFactor, FactorValue> getBaselineConditions(List<BioMaterial> samplesUsed, List<ExperimentalFactor> factors) {
Map<ExperimentalFactor, FactorValue> baselineConditions = ExpressionDataMatrixColumnSort.getBaselineLevels(samplesUsed, factors);
/*
* For factors that don't have an obvious baseline, use the first factorvalue.
*/
Collection<FactorValue> factorValuesOfFirstSample = samplesUsed.iterator().next().getFactorValues();
for (ExperimentalFactor factor : factors) {
if (!baselineConditions.containsKey(factor)) {
for (FactorValue biomf : factorValuesOfFirstSample) {
/*
* the first biomaterial has the values used as baseline
*/
if (biomf.getExperimentalFactor().equals(factor)) {
baselineConditions.put(factor, biomf);
}
}
}
}
return baselineConditions;
}
use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.
the class GeneralSearchControllerImpl method fillValueObjects.
@SuppressWarnings("unchecked")
private void fillValueObjects(Class<?> entityClass, List<SearchResult> results, SearchSettings settings) {
StopWatch timer = new StopWatch();
timer.start();
Collection<?> vos;
if (ExpressionExperiment.class.isAssignableFrom(entityClass)) {
vos = this.filterEE(expressionExperimentService.loadValueObjects(EntityUtils.getIds(results), false), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledEes((Collection<ExpressionExperimentValueObject>) vos);
}
} else if (ArrayDesign.class.isAssignableFrom(entityClass)) {
vos = this.filterAD(arrayDesignService.loadValueObjectsByIds(EntityUtils.getIds(results)), settings);
if (!SecurityUtil.isUserAdmin()) {
auditableUtil.removeTroubledArrayDesigns((Collection<ArrayDesignValueObject>) vos);
}
} else if (CompositeSequence.class.isAssignableFrom(entityClass)) {
Collection<CompositeSequenceValueObject> css = new ArrayList<>();
for (SearchResult sr : results) {
CompositeSequenceValueObject csvo = compositeSequenceService.loadValueObject((CompositeSequence) sr.getResultObject());
css.add(csvo);
}
vos = css;
} else if (BibliographicReference.class.isAssignableFrom(entityClass)) {
Collection<BibliographicReference> bss = bibliographicReferenceService.load(EntityUtils.getIds(results));
bss = bibliographicReferenceService.thaw(bss);
vos = bibliographicReferenceService.loadValueObjects(bss);
} else if (Gene.class.isAssignableFrom(entityClass)) {
Collection<Gene> genes = geneService.load(EntityUtils.getIds(results));
genes = geneService.thawLite(genes);
vos = geneService.loadValueObjects(genes);
} else if (Characteristic.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
Characteristic ch = (Characteristic) sr.getResultObject();
cvos.add(new CharacteristicValueObject(ch));
}
vos = cvos;
} else if (CharacteristicValueObject.class.isAssignableFrom(entityClass)) {
Collection<CharacteristicValueObject> cvos = new ArrayList<>();
for (SearchResult sr : results) {
CharacteristicValueObject ch = (CharacteristicValueObject) sr.getResultObject();
cvos.add(ch);
}
vos = cvos;
} else if (BioSequenceValueObject.class.isAssignableFrom(entityClass)) {
return;
} else if (GeneSet.class.isAssignableFrom(entityClass)) {
vos = geneSetService.getValueObjects(EntityUtils.getIds(results));
} else if (ExpressionExperimentSet.class.isAssignableFrom(entityClass)) {
vos = experimentSetService.loadValueObjects(experimentSetService.load(EntityUtils.getIds(results)));
} else if (FactorValue.class.isAssignableFrom(entityClass)) {
Collection<FactorValueValueObject> fvo = new ArrayList<>();
for (SearchResult sr : results) {
fvo.add(new FactorValueValueObject((FactorValue) sr.getResultObject()));
}
vos = fvo;
} else {
throw new UnsupportedOperationException("Don't know how to make value objects for class=" + entityClass);
}
if (vos == null || vos.isEmpty()) {
// it causing front end errors, if vos is empty make sure to get rid of all search results
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
it.next();
it.remove();
}
return;
}
// retained objects...
Map<Long, Object> idMap = EntityUtils.getIdMap(vos);
for (Iterator<SearchResult> it = results.iterator(); it.hasNext(); ) {
SearchResult sr = it.next();
if (!idMap.containsKey(sr.getId())) {
it.remove();
continue;
}
sr.setResultObject(idMap.get(sr.getId()));
}
if (timer.getTime() > 1000) {
BaseFormController.log.info("Value object conversion after search: " + timer.getTime() + "ms");
}
}
use of ubic.gemma.model.expression.experiment.FactorValue in project Gemma by PavlidisLab.
the class FactorValueDaoImpl method find.
@Override
public FactorValue find(FactorValue factorValue) {
try {
Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(FactorValue.class);
BusinessKey.checkKey(factorValue);
BusinessKey.createQueryObject(queryObject, factorValue);
java.util.List<?> results = queryObject.list();
Object result = null;
if (results != null) {
if (results.size() > 1) {
this.debug(results);
throw new org.springframework.dao.InvalidDataAccessResourceUsageException(results.size() + " instances of '" + FactorValue.class.getName() + "' was found when executing query for " + factorValue);
} else if (results.size() == 1) {
result = results.iterator().next();
}
}
return (FactorValue) result;
} catch (org.hibernate.HibernateException ex) {
throw super.convertHibernateAccessException(ex);
}
}
Aggregations