Search in sources :

Example 1 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class PlatformArg method getElements.

/**
 * Retrieves the Elements of the Platform that this argument represents.
 *
 * @param service service that will be used to retrieve the persistent AD object.
 * @return a collection of Composite Sequence VOs that the platform represented by this argument contains.
 */
public Collection<CompositeSequenceValueObject> getElements(ArrayDesignService service, CompositeSequenceService csService, int limit, int offset) {
    ArrayDesign ad = this.getPersistentObject(service);
    Collection<CompositeSequence> css = ad == null ? null : service.getCompositeSequences(ad, limit, offset);
    Collection<CompositeSequenceValueObject> csVos = new ArrayList<>(css != null ? css.size() : 0);
    if (css == null)
        return csVos;
    for (CompositeSequence cs : css) {
        CompositeSequenceValueObject csVo = csService.loadValueObject(cs);
        csVo.setGeneMappingSummaries(csService.getGeneMappingSummary(cs));
        csVos.add(csVo);
    }
    return csVos;
}
Also used : CompositeSequenceValueObject(ubic.gemma.model.expression.designElement.CompositeSequenceValueObject) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayList(java.util.ArrayList) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 2 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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 3 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence 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)

Example 4 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class PersistentDummyObjectHelper method getDesignElementDataVectors.

/**
 * @param bioAssays         BAs
 * @param ad                AD
 * @param ee                EE
 * @param quantitationTypes QTs
 * @return These are non-persistent
 */
private Collection<RawExpressionDataVector> getDesignElementDataVectors(ExpressionExperiment ee, Collection<QuantitationType> quantitationTypes, List<BioAssay> bioAssays, ArrayDesign ad) {
    BioAssayDimension baDim = BioAssayDimension.Factory.newInstance(ee.getShortName() + "_" + RandomStringUtils.randomAlphanumeric(20), null, bioAssays);
    Collection<RawExpressionDataVector> vectors = new HashSet<>();
    for (QuantitationType quantType : quantitationTypes) {
        for (CompositeSequence cs : ad.getCompositeSequences()) {
            RawExpressionDataVector vector = RawExpressionDataVector.Factory.newInstance();
            byte[] bdata = this.getDoubleData();
            vector.setData(bdata);
            vector.setDesignElement(cs);
            assert cs.getArrayDesign() != null;
            vector.setExpressionExperiment(ee);
            vector.setQuantitationType(quantType);
            vector.setBioAssayDimension(baDim);
            vectors.add(vector);
        }
    }
    return vectors;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 5 with CompositeSequence

use of ubic.gemma.model.expression.designElement.CompositeSequence in project Gemma by PavlidisLab.

the class AncovaTest method testAncovaWithInteraction.

/*
     * Two factors with interactions.
     */
@Test
public void testAncovaWithInteraction() {
    this.configureMocks();
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.getFactorsToInclude().add(this.experimentalFactorA_Area);
    config.getFactorsToInclude().add(this.experimentalFactorB);
    config.getInteractionsToInclude().add(config.getFactorsToInclude());
    Collection<DifferentialExpressionAnalysis> expressionAnalyses = analyzer.run(expressionExperiment, config);
    DifferentialExpressionAnalysis expressionAnalysis = expressionAnalyses.iterator().next();
    assertNotNull(expressionAnalysis);
    Collection<ExpressionAnalysisResultSet> resultSets = expressionAnalysis.getResultSets();
    assertEquals(3, resultSets.size());
    boolean foundInteractions = false;
    boolean foundContrast = false;
    for (ExpressionAnalysisResultSet resultSet : resultSets) {
        Collection<ExperimentalFactor> factors = resultSet.getExperimentalFactors();
        for (DifferentialExpressionAnalysisResult r : resultSet.getResults()) {
            CompositeSequence probe = r.getProbe();
            Double pvalue = r.getPvalue();
            assertNotNull(probe);
            Collection<ContrastResult> contrasts = r.getContrasts();
            Double stat;
            if (contrasts.isEmpty()) {
                continue;
            }
            stat = contrasts.iterator().next().getTstat();
            if (factors.size() == 2) {
                // interaction
                foundInteractions = true;
                switch(probe.getName()) {
                    case "probe_98":
                        assertEquals(0.7893, pvalue, 0.001);
                        break;
                    case "probe_10":
                        assertEquals(0.04514, pvalue, 0.0001);
                        break;
                    case "probe_4":
                        assertEquals(null, pvalue);
                        break;
                }
            } else {
                ExperimentalFactor f = factors.iterator().next();
                assertNotNull(f);
                if (f.equals(super.experimentalFactorA_Area)) {
                    switch(probe.getName()) {
                        case "probe_98":
                            assertEquals(0.8769, pvalue, 0.001);
                            break;
                        case "probe_10":
                            assertEquals(5.158e-10, pvalue, 1e-12);
                            break;
                        case "probe_4":
                            assertEquals(0.0048, pvalue, 0.0001);
                            assertNotNull(stat);
                            assertEquals(-125.746, stat, 0.001);
                            break;
                        case "probe_0":
                            assertEquals(1, r.getContrasts().size());
                            ContrastResult contrast = r.getContrasts().iterator().next();
                            assertEquals(super.factorValueA1, contrast.getFactorValue());
                            assertEquals(-202.5587, contrast.getLogFoldChange(), 0.001);
                            foundContrast = true;
                            break;
                    }
                } else {
                    if (probe.getName().equals("probe_98")) {
                        assertEquals(0.6888, pvalue, 0.001);
                    } else if (probe.getName().equals("probe_10")) {
                        assertEquals(0.07970, pvalue, 0.001);
                    }
                }
            }
        }
    }
    assertTrue(foundInteractions);
    assertTrue(foundContrast);
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) DifferentialExpressionAnalysis(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis) DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) Test(org.junit.Test)

Aggregations

CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)206 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)43 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)40 Gene (ubic.gemma.model.genome.Gene)32 Test (org.junit.Test)30 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)19 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)18 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)18 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)18 StopWatch (org.apache.commons.lang3.time.StopWatch)17 HashSet (java.util.HashSet)15 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 CompositeSequenceValueObject (ubic.gemma.model.expression.designElement.CompositeSequenceValueObject)15 ArrayList (java.util.ArrayList)14 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)14 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)13 Taxon (ubic.gemma.model.genome.Taxon)12 Collection (java.util.Collection)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)11