Search in sources :

Example 6 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class GeneIDbyTaxonEndpoint method invokeInternal.

/**
 * Reads the given <code>requestElement</code>, and sends 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);
    Collection<String> taxonResults = getSingleNodeValue(requestElement, "taxon_id");
    String taxonId = "";
    for (String id : taxonResults) {
        taxonId = id;
    }
    log.info("XML input read: taxon id, " + taxonId);
    // Get Gene matched with Taxon
    Taxon tax = taxonService.load(Long.parseLong(taxonId));
    if (tax == null) {
        String msg = "No taxon with id, " + taxonId + " can be found.";
        return buildBadResponse(document, msg);
    }
    Collection<Gene> geneCollection = geneService.loadAll(tax);
    // build results in the form of a collection
    Collection<String> geneIds = new HashSet<String>();
    for (Gene gene : geneCollection) {
        geneIds.add(gene.getId().toString());
    }
    Element wrapper = buildWrapper(document, geneIds, "gene_ids");
    watch.stop();
    Long time = watch.getTime();
    log.info("XML response for gene id results built in " + time + "ms.");
    return wrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) StopWatch(org.apache.commons.lang3.time.StopWatch) HashSet(java.util.HashSet)

Example 7 with Gene

use of ubic.gemma.model.genome.Gene 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)

Example 8 with Gene

use of ubic.gemma.model.genome.Gene 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;
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch) Gene(ubic.gemma.model.genome.Gene) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentValueObject(ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet)

Example 9 with Gene

use of ubic.gemma.model.genome.Gene 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;
}
Also used : Gene(ubic.gemma.model.genome.Gene) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) Element(org.w3c.dom.Element) Document(org.w3c.dom.Document) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 10 with Gene

use of ubic.gemma.model.genome.Gene in project Gemma by PavlidisLab.

the class Gene2ProbeEndpoint 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(Gene2ProbeEndpoint.PROBE_LOCAL_NAME);
    // OLDFIXME this should take gene_id
    String geneSymbol = "";
    Collection<String> geneResults = this.getSingleNodeValue(requestElement, "gene_official_symbol");
    for (String id : geneResults) {
        geneSymbol = id;
    }
    String taxonid = "";
    Collection<String> taxonResults = this.getSingleNodeValue(requestElement, "taxon_id");
    for (String id : taxonResults) {
        taxonid = id;
    }
    Gene2ProbeEndpoint.log.info("XML iput read: Gene symbol, " + geneSymbol + " & taxon id, " + taxonid);
    // get the probe and array design info
    // get taxon
    Taxon taxon = taxonService.load(Long.parseLong(taxonid));
    if (taxon == null) {
        String msg = "No taxon with id, " + taxonid + ", can be found.";
        return this.buildBadResponse(document, msg);
    }
    // get gene, gven taxon and symbol
    Gene gene = geneService.findByOfficialSymbol(geneSymbol, taxon);
    if (gene == null) {
        String msg = "No gene with symbol, " + geneSymbol + ", can be found.";
        return this.buildBadResponse(document, msg);
    }
    // get probe
    Collection<CompositeSequence> csCol = compositeSequenceService.findByGene(gene);
    if (csCol == null || csCol.isEmpty()) {
        String msg = "No composite sequence can be found.";
        return this.buildBadResponse(document, msg);
    }
    // start building the wrapper
    // build xml manually rather than use buildWrapper inherited from
    // AbstractGemmeEndpoint
    String elementName1 = "probe_id";
    String elementName2 = "array_design_identifier";
    Element responseWrapper = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, Gene2ProbeEndpoint.PROBE_LOCAL_NAME);
    Element responseElement = document.createElementNS(AbstractGemmaEndpoint.NAMESPACE_URI, Gene2ProbeEndpoint.PROBE_LOCAL_NAME + AbstractGemmaEndpoint.RESPONSE);
    responseWrapper.appendChild(responseElement);
    for (CompositeSequence cs : csCol) {
        // CompositeSequence id
        String elementString1 = cs.getId().toString();
        // corresponding ArrayDesign identifier
        String elementString2 = cs.getArrayDesign().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( "Finished generating result. Sending response to client." );
    Gene2ProbeEndpoint.log.info("XML response for Probe result built in " + time + "ms.");
    return responseWrapper;
}
Also used : Gene(ubic.gemma.model.genome.Gene) Taxon(ubic.gemma.model.genome.Taxon) Element(org.w3c.dom.Element) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

Gene (ubic.gemma.model.genome.Gene)186 Taxon (ubic.gemma.model.genome.Taxon)34 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)32 StopWatch (org.apache.commons.lang3.time.StopWatch)31 Test (org.junit.Test)24 HashSet (java.util.HashSet)23 GeneProduct (ubic.gemma.model.genome.gene.GeneProduct)20 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)18 Element (org.w3c.dom.Element)16 ArrayList (java.util.ArrayList)13 Transactional (org.springframework.transaction.annotation.Transactional)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)12 Collection (java.util.Collection)11 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)11 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)10 HashMap (java.util.HashMap)8 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioSequence2GeneProduct (ubic.gemma.model.association.BioSequence2GeneProduct)7 PhysicalLocation (ubic.gemma.model.genome.PhysicalLocation)7 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)7