use of ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject 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.arrayDesign.ArrayDesignValueObject in project Gemma by PavlidisLab.
the class ArrayDesignFormController method formBackingObject.
/**
* Case = GET: Step 1 - return instance of command class (from database). This is not called in the POST case
* because the sessionForm is set to 'true' in the constructor. This means the command object was already bound to
* the session in the GET case.
*
* @param request http request
* @return Object
*/
@Override
protected Object formBackingObject(HttpServletRequest request) {
String idString = request.getParameter("id");
Long id;
ArrayDesignValueObject arrayDesign = null;
// should be caught by validation.
if (idString != null) {
try {
id = Long.parseLong(idString);
} catch (NumberFormatException e) {
throw new IllegalArgumentException();
}
Collection<Long> ids = new HashSet<Long>();
ids.add(id);
Collection<ArrayDesignValueObject> arrayDesigns = arrayDesignService.loadValueObjectsByIds(ids);
if (arrayDesigns.size() > 0)
arrayDesign = arrayDesigns.iterator().next();
}
if (arrayDesign == null) {
return new ArrayDesignValueObject(-1L);
}
return arrayDesign;
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject in project Gemma by PavlidisLab.
the class ArrayDesignReportServiceImpl method fillInSubsumptionInfo.
@Override
public void fillInSubsumptionInfo(Collection<ArrayDesignValueObject> valueObjects) {
Collection<Long> ids = new ArrayList<>();
for (Object object : valueObjects) {
if (object == null)
continue;
ArrayDesignValueObject adVo = (ArrayDesignValueObject) object;
ids.add(adVo.getId());
}
Map<Long, Boolean> isSubsumed = arrayDesignService.isSubsumed(ids);
Map<Long, Boolean> hasSubsumees = arrayDesignService.isSubsumer(ids);
Map<Long, Boolean> isMergee = arrayDesignService.isMergee(ids);
Map<Long, Boolean> isMerged = arrayDesignService.isMerged(ids);
for (ArrayDesignValueObject adVo : valueObjects) {
Long id = adVo.getId();
if (isSubsumed.containsKey(id)) {
adVo.setIsSubsumed(isSubsumed.get(id));
}
if (hasSubsumees.containsKey(id)) {
adVo.setIsSubsumer(hasSubsumees.get(id));
}
if (isMergee.containsKey(id)) {
adVo.setIsMergee(isMergee.get(id));
}
if (isMerged.containsKey(id)) {
adVo.setIsMerged(isMerged.get(id));
}
}
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject in project Gemma by PavlidisLab.
the class ArrayDesignReportServiceImpl method fillInValueObjects.
/**
* Fill in the probe summary statistics
*/
@Override
public void fillInValueObjects(Collection<ArrayDesignValueObject> adVos) {
for (ArrayDesignValueObject origVo : adVos) {
if (origVo == null)
continue;
ArrayDesignValueObject cachedVo = this.getSummaryObject(origVo.getId());
if (cachedVo != null) {
origVo.setNumProbeSequences(cachedVo.getNumProbeSequences());
origVo.setNumProbeAlignments(cachedVo.getNumProbeAlignments());
origVo.setNumProbesToGenes(cachedVo.getNumProbesToGenes());
origVo.setNumGenes(cachedVo.getNumGenes());
origVo.setDateCached(cachedVo.getDateCached());
origVo.setDesignElementCount(cachedVo.getDesignElementCount());
}
}
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesignValueObject in project Gemma by PavlidisLab.
the class ArrayDesignReportServiceImpl method generateAllArrayDesignReport.
@Override
public void generateAllArrayDesignReport() {
ArrayDesignReportServiceImpl.log.info("Generating report summarizing all platforms ... ");
// obtain time information (for timestamp)
Date d = new Date(System.currentTimeMillis());
String timestamp = DateFormatUtils.format(d, "yyyy.MM.dd HH:mm");
long numCsBioSequences = arrayDesignService.numAllCompositeSequenceWithBioSequences();
long numCsBlatResults = arrayDesignService.numAllCompositeSequenceWithBlatResults();
long numCsGenes = arrayDesignService.numAllCompositeSequenceWithGenes();
long numGenes = arrayDesignService.numAllGenes();
// create a surrogate ArrayDesignValue object to represent the total of all platforms
ArrayDesignValueObject adVo = new ArrayDesignValueObject(-1L);
adVo.setNumProbeSequences(Long.toString(numCsBioSequences));
adVo.setNumProbeAlignments(Long.toString(numCsBlatResults));
adVo.setNumProbesToGenes(Long.toString(numCsGenes));
adVo.setNumGenes(Long.toString(numGenes));
adVo.setDateCached(timestamp);
// remove file first
File f = new File(ArrayDesignReportServiceImpl.HOME_DIR + File.separatorChar + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_DIR + File.separatorChar + ArrayDesignReportServiceImpl.ARRAY_DESIGN_SUMMARY);
if (f.exists()) {
if (!f.canWrite() || !f.delete()) {
ArrayDesignReportServiceImpl.log.warn("Cannot write to file.");
return;
}
}
try (FileOutputStream fos = new FileOutputStream(ArrayDesignReportServiceImpl.HOME_DIR + File.separatorChar + ArrayDesignReportServiceImpl.ARRAY_DESIGN_REPORT_DIR + File.separatorChar + ArrayDesignReportServiceImpl.ARRAY_DESIGN_SUMMARY);
ObjectOutputStream oos = new ObjectOutputStream(fos)) {
oos.writeObject(adVo);
} catch (Throwable e) {
// cannot write to file. Just fail gracefully.
ArrayDesignReportServiceImpl.log.error("Cannot write to file.");
}
ArrayDesignReportServiceImpl.log.info("Done making reports");
}
Aggregations