Search in sources :

Example 1 with RankMethod

use of ubic.gemma.persistence.service.expression.bioAssayData.ProcessedExpressionDataVectorDao.RankMethod 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;
}
Also used : Element(org.w3c.dom.Element) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch) Gene(ubic.gemma.model.genome.Gene) RankMethod(ubic.gemma.persistence.service.expression.bioAssayData.ProcessedExpressionDataVectorDao.RankMethod) HashSet(java.util.HashSet)

Aggregations

HashSet (java.util.HashSet)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 Element (org.w3c.dom.Element)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 Gene (ubic.gemma.model.genome.Gene)1 RankMethod (ubic.gemma.persistence.service.expression.bioAssayData.ProcessedExpressionDataVectorDao.RankMethod)1