use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.
the class DatasetsRestTest method testAll.
@Test
public void testAll() {
ResponseDataObject response = datasetsWebService.all(DatasetFilterArg.valueOf(""), IntArg.valueOf("5"), IntArg.valueOf("5"), SortArg.valueOf("+id"), new MockHttpServletResponse());
assertNotNull(response.getData());
assertTrue(response.getData() instanceof Collection<?>);
assertEquals(5, ((Collection) response.getData()).size());
assertTrue(((Collection) response.getData()).iterator().next() instanceof ExpressionExperimentValueObject);
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.
the class DifferentialExpressionProbeResultEndpoint method invokeInternal.
/**
* Reads the given <code>requestElement</code>, and sends a the response back.
*
* @param requestElement the contents of the SOAP message as DOM elements
* @param document a DOM document to be used for constructing <code>Node</code>s
* @return the response element
*/
@Override
protected Element invokeInternal(Element requestElement, Document document) {
StopWatch watch = new StopWatch();
watch.start();
setLocalName(LOCAL_NAME);
// taxon input
Collection<String> taxonInput = getSingleNodeValue(requestElement, "taxon_id");
String taxonId = "";
for (String id : taxonInput) {
taxonId = id;
}
Taxon taxon = taxonService.load(Long.parseLong(taxonId));
if (taxon == null) {
String msg = "No taxon with id, " + taxonId + ", can be found.";
return buildBadResponse(document, msg);
}
// gene ids input
Collection<String> geneInput = getArrayValues(requestElement, "gene_ids");
Collection<Long> geneIDLong = new HashSet<Long>();
for (String id : geneInput) geneIDLong.add(Long.parseLong(id));
Collection<Gene> rawGeneCol = geneService.loadThawed(geneIDLong);
if (rawGeneCol.isEmpty()) {
String msg = "None of the gene id's can be found.";
return buildBadResponse(document, msg);
}
Collection<Gene> geneCol = retainGenesInCorrectTaxon(rawGeneCol, taxon);
if (geneCol == null || geneCol.isEmpty()) {
String msg = "Input genes do not match input taxon.";
return buildBadResponse(document, msg);
}
// expression experiment set id input
Collection<String> analysisInput = getSingleNodeValue(requestElement, "expression_experiment_set_id");
String analysisId = "";
for (String id : analysisInput) {
analysisId = id;
}
ExpressionExperimentSet ees = expressionExperimentSetService.load(Long.parseLong(analysisId));
if (ees == null) {
String msg = "No matching expression experiment set can be found for id, " + analysisId;
return buildBadResponse(document, msg);
}
if (!(ees.getTaxon().getId()).equals(taxon.getId())) {
String msg = "Expression experiment set " + analysisId + " does not match input taxon " + taxon.getCommonName();
return buildBadResponse(document, msg);
}
Collection<ExpressionExperiment> eeCol = getExperiments(ees);
Collection<BioAssaySet> bioAssaySets = new HashSet<BioAssaySet>();
bioAssaySets.addAll(eeCol);
// threshold input
Collection<String> thresholdInput = getSingleNodeValue(requestElement, "threshold");
String threshold = "";
for (String id : thresholdInput) {
threshold = id;
}
log.info("XML input read: " + geneInput.size() + " gene ids, & taxon id " + taxonId + ", & expression experiment set id " + analysisId + ", and threshold " + threshold);
Element responseWrapper = document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
Element responseElement = document.createElementNS(NAMESPACE_URI, LOCAL_NAME + RESPONSE);
responseWrapper.appendChild(responseElement);
for (Gene gene : geneCol) {
Map<ExpressionExperimentValueObject, List<DifferentialExpressionValueObject>> results = differentialExpressionResultService.find(gene, EntityUtils.getIds(bioAssaySets), Double.parseDouble(threshold), null);
for (ExpressionExperimentValueObject ee : results.keySet()) {
// main call to the DifferentialExpressionAnalysisService to retrieve
// DifferentialExpressionAnalysisResultSet collection
Collection<DifferentialExpressionValueObject> parCol = results.get(ee);
// check that a DifferentialExpressionAnalysisResult is not null
if (parCol == null || parCol.isEmpty()) {
log.error("No probe analysis results can be found for gene: " + gene.getOfficialSymbol() + " & experiment: " + ee);
buildXMLResponse(document, responseElement, gene.getId().toString(), ee.getId().toString(), null);
} else
buildXMLResponse(document, responseElement, gene.getId().toString(), ee.getId().toString(), parCol);
}
}
watch.stop();
Long time = watch.getTime();
log.info("XML response for differential expression probe results built in " + time + "ms.");
return responseWrapper;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject in project Gemma by PavlidisLab.
the class SVDServiceHelperImpl method getTopLoadedVectors.
@Override
public Map<ProbeLoading, DoubleVectorValueObject> getTopLoadedVectors(ExpressionExperiment ee, int component, int count) {
PrincipalComponentAnalysis pca = principalComponentAnalysisService.loadForExperiment(ee);
Map<ProbeLoading, DoubleVectorValueObject> result = new HashMap<>();
if (pca == null) {
return result;
}
List<ProbeLoading> topLoadedProbes = principalComponentAnalysisService.getTopLoadedProbes(ee, component, count);
if (topLoadedProbes == null) {
SVDServiceHelperImpl.log.warn("No probes?");
return result;
}
Map<Long, ProbeLoading> probes = new LinkedHashMap<>();
Set<CompositeSequence> p = new HashSet<>();
for (ProbeLoading probeLoading : topLoadedProbes) {
CompositeSequence probe = probeLoading.getProbe();
probes.put(probe.getId(), probeLoading);
p.add(probe);
}
if (probes.isEmpty())
return result;
assert probes.size() <= count;
Collection<ExpressionExperiment> ees = new HashSet<>();
ees.add(ee);
Collection<DoubleVectorValueObject> dvVos = processedExpressionDataVectorService.getProcessedDataArraysByProbe(ees, p);
if (dvVos.isEmpty()) {
SVDServiceHelperImpl.log.warn("No vectors came back from the call; check the Gene2CS table?");
return result;
}
// note that this might have come from a cache.
/*
* This is actually expected, because we go through the genes.
*/
BioAssayDimension bioAssayDimension = pca.getBioAssayDimension();
assert bioAssayDimension != null;
assert !bioAssayDimension.getBioAssays().isEmpty();
for (DoubleVectorValueObject vct : dvVos) {
ProbeLoading probeLoading = probes.get(vct.getDesignElement().getId());
if (probeLoading == null) {
/*
* This is okay, we will skip this probe. It was another probe for a gene that _was_ highly loaded.
*/
continue;
}
assert bioAssayDimension.getBioAssays().size() == vct.getData().length;
vct.setRank(probeLoading.getLoadingRank().doubleValue());
vct.setExpressionExperiment(new ExpressionExperimentValueObject(ee));
result.put(probeLoading, vct);
}
if (result.isEmpty()) {
SVDServiceHelperImpl.log.warn("No results, something went wrong; there were " + dvVos.size() + " vectors to start but they all got filtered out.");
}
return result;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject 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.ExpressionExperimentValueObject in project Gemma by PavlidisLab.
the class BibliographicReferenceControllerImpl method showAllForExperiments.
@Override
public ModelAndView showAllForExperiments(HttpServletRequest request, HttpServletResponse response) {
Map<ExpressionExperiment, BibliographicReference> eeToBibRefs = bibliographicReferenceService.getAllExperimentLinkedReferences();
// map sorted in natural order of the keys
SortedMap<CitationValueObject, Collection<ExpressionExperimentValueObject>> citationToEEs = new TreeMap<>();
for (Entry<ExpressionExperiment, BibliographicReference> entry : eeToBibRefs.entrySet()) {
if (entry.getValue().getTitle() == null || entry.getValue().getTitle().isEmpty() || entry.getValue().getAuthorList() == null || entry.getValue().getAuthorList().isEmpty()) {
continue;
}
CitationValueObject cvo = CitationValueObject.convert2CitationValueObject(entry.getValue());
if (!citationToEEs.containsKey(cvo)) {
citationToEEs.put(cvo, new ArrayList<ExpressionExperimentValueObject>());
}
ExpressionExperiment ee = entry.getKey();
ee.setBioAssays(null);
ee.setAccession(null);
ee.setExperimentalDesign(null);
citationToEEs.get(cvo).add(new ExpressionExperimentValueObject(ee));
}
return new ModelAndView("bibRefAllExperiments").addObject("citationToEEs", citationToEEs);
}
Aggregations