Search in sources :

Example 31 with DoubleVectorValueObject

use of ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject in project Gemma by PavlidisLab.

the class DEDVfromEEIDGeneIDEndpoint 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(DEDVfromEEIDGeneIDEndpoint.EXPERIMENT_LOCAL_NAME);
    // get ee id's from request
    Collection<String> eeIdResult = this.getArrayValues(requestElement, "ee_ids");
    Collection<Long> eeIDLong = new HashSet<>();
    for (String id : eeIdResult) eeIDLong.add(Long.parseLong(id));
    // Need to get and thawRawAndProcessed the experiments.
    Collection<ExpressionExperiment> eeObjs = expressionExperimentService.load(eeIDLong);
    for (ExpressionExperiment ee : eeObjs) {
        ee = expressionExperimentService.thawLite(ee);
    }
    // get gene id's from request
    Collection<String> geneIdResult = this.getArrayValues(requestElement, "gene_ids");
    Collection<Long> geneIDLong = new HashSet<>();
    for (String id : geneIdResult) geneIDLong.add(Long.parseLong(id));
    DEDVfromEEIDGeneIDEndpoint.log.debug("XML input read: " + eeIdResult.size() + " experiment ids & " + geneIdResult.size() + " gene ids");
    Collection<DoubleVectorValueObject> vectors = processedExpressionDataVectorService.getProcessedDataArrays(eeObjs, geneIDLong);
    // start building the wrapper
    // xml is built manually here instead of using the buildWrapper method inherited from AbstractGemmaEndpoint
    // log.info( "Building " + EXPERIMENT_LOCAL_NAME + " XML response" );
    String elementName1 = "dedv";
    String elementName2 = "geneIdList";
    String elementName3 = "eeIdList";
    Element responseWrapper = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, DEDVfromEEIDGeneIDEndpoint.EXPERIMENT_LOCAL_NAME);
    Element responseElement = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, DEDVfromEEIDGeneIDEndpoint.EXPERIMENT_LOCAL_NAME + AbstractGemmaEndpoint.RESPONSE);
    responseWrapper.appendChild(responseElement);
    if (vectors == null || vectors.isEmpty())
        return this.buildBadResponse(document, "No " + elementName1 + " result");
    // of the design elements
    for (DoubleVectorValueObject dedv : vectors) {
        double[] convertedDEDV = dedv.getData();
        // data vector string for output
        String elementString1 = this.encode(convertedDEDV);
        // 
        Collection<Long> geneidCol = dedv.getGenes();
        // gene ids, space delimited for output
        String elementString2 = this.encode(geneidCol.toArray());
        String elementString3 = dedv.getExpressionExperiment().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);
        Element e3 = document.createElement(elementName3);
        e3.appendChild(document.createTextNode(elementString3));
        responseElement.appendChild(e3);
    }
    watch.stop();
    Long time = watch.getTime();
    // log.info( "Finished generating result. Sending response to client." );
    DEDVfromEEIDGeneIDEndpoint.log.debug("XML response for design element data vector results built in " + time + "ms.");
    // log.info( "Finished generating matrix. Sending response to client." );
    // naming convention for the xml file report
    String filename = "dedv-";
    if (geneIDLong.size() > 10)
        filename = filename.concat(geneIDLong.size() + "-" + eeIdResult.size());
    else {
        for (String id : geneIdResult) filename = filename.concat(id + "-");
        filename = filename.concat("" + eeIdResult.size());
    }
    this.writeReport(responseWrapper, document, filename);
    return responseWrapper;
}
Also used : Element(org.w3c.dom.Element) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) HashSet(java.util.HashSet)

Aggregations

DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)31 StopWatch (org.apache.commons.lang3.time.StopWatch)13 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)9 Test (org.junit.Test)6 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)6 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)6 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)5 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)5 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)5 Gene (ubic.gemma.model.genome.Gene)5 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)4 ExperimentExpressionLevelsValueObject (ubic.gemma.model.expression.bioAssayData.ExperimentExpressionLevelsValueObject)4 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)4 InputStream (java.io.InputStream)3 Transactional (org.springframework.transaction.annotation.Transactional)3 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)3 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)3 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)3 ProbeLoading (ubic.gemma.model.analysis.expression.pca.ProbeLoading)3 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)3