use of ubic.gemma.model.expression.designElement.CompositeSequenceValueObject in project Gemma by PavlidisLab.
the class PlatformArg method getElements.
/**
* Retrieves the Elements of the Platform that this argument represents.
*
* @param service service that will be used to retrieve the persistent AD object.
* @return a collection of Composite Sequence VOs that the platform represented by this argument contains.
*/
public Collection<CompositeSequenceValueObject> getElements(ArrayDesignService service, CompositeSequenceService csService, int limit, int offset) {
ArrayDesign ad = this.getPersistentObject(service);
Collection<CompositeSequence> css = ad == null ? null : service.getCompositeSequences(ad, limit, offset);
Collection<CompositeSequenceValueObject> csVos = new ArrayList<>(css != null ? css.size() : 0);
if (css == null)
return csVos;
for (CompositeSequence cs : css) {
CompositeSequenceValueObject csVo = csService.loadValueObject(cs);
csVo.setGeneMappingSummaries(csService.getGeneMappingSummary(cs));
csVos.add(csVo);
}
return csVos;
}
use of ubic.gemma.model.expression.designElement.CompositeSequenceValueObject 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.designElement.CompositeSequenceValueObject in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method maskAndUnpack.
private Map<CompositeSequence, DoubleVectorValueObject> maskAndUnpack(Collection<RawExpressionDataVector> preferredData, Collection<RawExpressionDataVector> missingValueData) {
Map<CompositeSequence, DoubleVectorValueObject> unpackedData = this.unpack(preferredData);
if (missingValueData.size() == 0) {
AbstractDao.log.info("There is no separate missing data information, simply using the data as is");
for (DoubleVectorValueObject rv : unpackedData.values()) {
rv.setMasked(true);
}
return unpackedData;
}
Collection<BooleanVectorValueObject> unpackedMissingValueData = this.unpackBooleans(missingValueData);
Map<CompositeSequenceValueObject, BooleanVectorValueObject> missingValueMap = new HashMap<>();
for (BooleanVectorValueObject bv : unpackedMissingValueData) {
missingValueMap.put(bv.getDesignElement(), bv);
}
boolean warned = false;
for (DoubleVectorValueObject rv : unpackedData.values()) {
double[] data = rv.getData();
CompositeSequenceValueObject de = rv.getDesignElement();
BooleanVectorValueObject mv = missingValueMap.get(de);
if (mv == null) {
if (!warned && AbstractDao.log.isWarnEnabled())
AbstractDao.log.warn("No mask vector for " + de + ", additional warnings for missing masks for this job will be skipped");
// we're missing a mask vector for it for some reason, but still flag it as effectively masked.
rv.setMasked(true);
warned = true;
continue;
}
boolean[] mvData = mv.getData();
if (mvData.length != data.length) {
throw new IllegalStateException("Missing value data didn't match data length");
}
for (int i = 0; i < data.length; i++) {
if (!mvData[i]) {
data[i] = Double.NaN;
}
}
rv.setMasked(true);
}
return unpackedData;
}
use of ubic.gemma.model.expression.designElement.CompositeSequenceValueObject in project Gemma by PavlidisLab.
the class CompositeSequenceDaoImpl method loadValueObjectsPreFilter.
@Override
public Collection<CompositeSequenceValueObject> loadValueObjectsPreFilter(int offset, int limit, String orderBy, boolean asc, ArrayList<ObjectFilter[]> filter) {
// Compose query
Query query = this.getLoadValueObjectsQueryString(filter, orderBy, !asc);
query.setCacheable(true);
if (limit > 0)
query.setMaxResults(limit);
query.setFirstResult(offset);
// noinspection unchecked
List<Object[]> list = query.list();
List<CompositeSequenceValueObject> vos = new ArrayList<>(list.size());
for (Object[] row : list) {
CompositeSequence cs = (CompositeSequence) row[1];
cs.setArrayDesign((ArrayDesign) row[2]);
CompositeSequenceValueObject vo = new CompositeSequenceValueObject(cs);
vos.add(vo);
}
return vos;
}
use of ubic.gemma.model.expression.designElement.CompositeSequenceValueObject 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