use of ubic.gemma.model.expression.experiment.ExpressionExperiment in project Gemma by PavlidisLab.
the class DEDVRankEndpoint 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();
this.setLocalName(DEDVRankEndpoint.LOCAL_NAME);
// get ee id's from request
Collection<String> eeIdInput = this.getArrayValues(requestElement, "ee_ids");
Collection<Long> eeIDLong = new HashSet<>();
for (String id : eeIdInput) eeIDLong.add(Long.parseLong(id));
// Need to get and thawRawAndProcessed the experiments.
Collection<ExpressionExperiment> eeInput = expressionExperimentService.load(eeIDLong);
if (eeInput == null || eeInput.isEmpty())
return this.buildBadResponse(document, "Expression experiment(s) cannot be found or incorrect input");
// get gene id's from request
Collection<String> geneIdInput = this.getArrayValues(requestElement, "gene_ids");
Collection<Long> geneIDLong = new HashSet<>();
for (String id : geneIdInput) geneIDLong.add(Long.parseLong(id));
Collection<Gene> geneInput = geneService.load(geneIDLong);
if (geneInput == null || geneInput.isEmpty())
return this.buildBadResponse(document, "Gene(s) cannot be found or incorrect input");
// get method - max or mean.
Collection<String> methodIn = this.getSingleNodeValue(requestElement, "method");
// expect one value only
String methodString = "";
for (String type : methodIn) methodString = type;
RankMethod method = this.getMethod(methodString);
if (method == null)
return this.buildBadResponse(document, "Incorrect method input");
DEDVRankEndpoint.log.info("XML input read: " + eeInput.size() + " experiment ids & " + geneInput.size() + " gene ids" + " and method: " + methodString);
// main call to expressionDataMatrixService to obtain rank results
DoubleMatrix<Gene, ExpressionExperiment> rankMatrix = expressionDataMatrixService.getRankMatrix(geneInput, eeInput, method);
// start building the wrapper
// xml is built manually here instead of using the buildWrapper method inherited from AbstractGemmaEndpoint
Element responseWrapper = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, DEDVRankEndpoint.LOCAL_NAME);
Element responseElement = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, DEDVRankEndpoint.LOCAL_NAME + AbstractGemmaEndpoint.RESPONSE);
responseWrapper.appendChild(responseElement);
if (rankMatrix == null)
return this.buildBadResponse(document, "No ranking result");
// -build single-row Collections to use for ExpressionDataMatrixBuilder
// -need to do this so that we can use the .getPreferredData()
// also necessary to do each data vector at a time because we
// already have a mapping to the genes
// of the design elements
Collection<Gene> rowNames = rankMatrix.getRowNames();
Collection<ExpressionExperiment> colNames = rankMatrix.getColNames();
// boolean eeTrack = false;
for (Gene geneRow : rowNames) {
Element e1 = document.createElement("gene_ids");
e1.appendChild(document.createTextNode(geneRow.getId().toString()));
responseElement.appendChild(e1);
double[] rowData = rankMatrix.getRowByName(geneRow);
Element e2 = document.createElement("ranks");
e2.appendChild(document.createTextNode(this.encode(rowData)));
responseElement.appendChild(e2);
}
for (ExpressionExperiment ee : colNames) {
Element e3 = document.createElement("ee_ids");
e3.appendChild(document.createTextNode(ee.getId().toString()));
responseElement.appendChild(e3);
}
watch.stop();
Long time = watch.getTime();
DEDVRankEndpoint.log.debug("XML response for dedv rank results built in " + time + "ms.");
return responseWrapper;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperiment 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.ExpressionExperiment in project Gemma by PavlidisLab.
the class ExperimentDEDVEndpoint 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) throws Exception {
StopWatch watch = new StopWatch();
watch.start();
setLocalName(EXPERIMENT_LOCAL_NAME);
String eeid = "";
Collection<String> eeResults = getSingleNodeValue(requestElement, "ee_id");
for (String id : eeResults) {
eeid = id;
}
// Check to make sure we haven't already generated this EE report.
Document doc = readReport(DEFAULT_FILENAME + eeid + DEFAULT_EXTENSION);
if (doc != null) {
// Successfully got report from disk
watch.stop();
Long time = watch.getTime();
log.info("XML response for ee" + eeid + " retrieved from disk in " + time + "ms.");
return doc.getDocumentElement();
}
// Build the matrix
ExpressionExperiment ee = expressionExperimentService.load(Long.parseLong(eeid));
ee = expressionExperimentService.thawLite(ee);
ExpressionDataDoubleMatrix dmatrix = expressionDataMatrixService.getProcessedExpressionDataMatrix(ee);
// start building the wrapper
// build xml manually rather than use buildWrapper inherited from AbstractGemmeEndpoint
String elementName1 = "dedv";
String elementName2 = "geneIdist";
// log.info( "Building " + EXPERIMENT_LOCAL_NAME + " XML response" );
Element responseWrapper = document.createElementNS(NAMESPACE_URI, EXPERIMENT_LOCAL_NAME);
Element responseElement = document.createElementNS(NAMESPACE_URI, EXPERIMENT_LOCAL_NAME + RESPONSE);
responseWrapper.appendChild(responseElement);
if (dmatrix == null || (dmatrix.rows() == 0))
responseElement.appendChild(document.createTextNode("No " + elementName1 + " result"));
else {
for (int rowNum = 0; rowNum < dmatrix.rows(); rowNum++) {
// data vector string for output
String elementString1 = encode(dmatrix.getRow(rowNum));
String elementString2 = "";
CompositeSequence de = dmatrix.getDesignElementForRow(rowNum);
Collection<Gene> geneCol = compositeSequenceService.getGenes(de);
for (Gene gene : geneCol) {
if (elementString2.equals(""))
elementString2 = elementString2.concat(gene.getId().toString());
else
elementString2 = elementString2.concat(DELIMITER + gene.getId().toString());
}
Element e1 = document.createElement(elementName1);
e1.appendChild(document.createTextNode(elementString1));
responseElement.appendChild(e1);
Element e2 = document.createElement(elementName2);
e2.appendChild(document.createTextNode(elementString2));
responseElement.appendChild(e2);
}
}
watch.stop();
Long time = watch.getTime();
log.info("XML response for ee:" + eeid + " created from scratch in " + time + "ms.");
writeReport(responseWrapper, document, DEFAULT_FILENAME + eeid);
return responseWrapper;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperiment in project Gemma by PavlidisLab.
the class ExperimentIdEndpoint 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(EXPERIMENT_LOCAL_NAME);
String eeName = "";
Collection<String> eeResults = getSingleNodeValue(requestElement, "ee_short_name");
for (String id : eeResults) {
eeName = id;
}
log.debug("XML input read: expression experiment shortname, " + eeName);
ExpressionExperiment ee = expressionExperimentService.findByShortName(eeName);
if (ee == null) {
String msg = "No Expression Experiment with short name, " + eeName + " can be found.";
return buildBadResponse(document, msg);
}
// get Array Design ID and build results in the form of a collection
Collection<String> eeId = new HashSet<String>();
eeId.add(ee.getId().toString());
Element wrapper = buildWrapper(document, eeId, "ee_id");
watch.stop();
Long time = watch.getTime();
log.debug("XML response for Expression Experiment Id result built in " + time + "ms.");
return wrapper;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperiment in project Gemma by PavlidisLab.
the class SearchServiceImpl method filterCharacteristicOwnersByClass.
private Collection<SearchResult> filterCharacteristicOwnersByClass(Collection<Class<?>> classes, Map<Characteristic, Object> characteristic2entity) {
Collection<BioMaterial> biomaterials = new HashSet<>();
Collection<FactorValue> factorValues = new HashSet<>();
Collection<SearchResult> results = new HashSet<>();
for (Characteristic c : characteristic2entity.keySet()) {
Object o = characteristic2entity.get(c);
for (Class<?> clazz : classes) {
if (clazz.isAssignableFrom(o.getClass())) {
String matchedText = c.getValue();
if (o instanceof BioMaterial) {
biomaterials.add((BioMaterial) o);
} else if (o instanceof FactorValue) {
factorValues.add((FactorValue) o);
} else {
if (c instanceof VocabCharacteristic && c.getValueUri() != null) {
matchedText = "Ontology term: <a href=\"" + Settings.getRootContext() + "/searcher.html?query=" + c.getValueUri() + "\">" + matchedText + "</a>";
}
results.add(new SearchResult(o, 1.0, matchedText));
}
}
}
}
this.addEEeByFactorvalues(results, factorValues);
if (biomaterials.size() > 0) {
Collection<ExpressionExperiment> ees = expressionExperimentService.findByBioMaterials(biomaterials);
for (ExpressionExperiment ee : ees) {
results.add(new SearchResult(ee, SearchServiceImpl.INDIRECT_DB_HIT_PENALTY, "BioMaterial characteristic"));
}
}
return results;
}
Aggregations