Search in sources :

Example 16 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class ExpressionAnalysisResultSetDaoImpl method thawFully.

@Override
public DifferentialExpressionAnalysis thawFully(DifferentialExpressionAnalysis differentialExpressionAnalysis) {
    StopWatch timer = new StopWatch();
    timer.start();
    differentialExpressionAnalysis = (DifferentialExpressionAnalysis) this.getSessionFactory().getCurrentSession().load(DifferentialExpressionAnalysis.class, differentialExpressionAnalysis.getId());
    Collection<ExpressionAnalysisResultSet> thawed = new HashSet<>();
    for (ExpressionAnalysisResultSet rs : differentialExpressionAnalysis.getResultSets()) {
        thawed.add(this.thaw(rs));
    }
    boolean changed = differentialExpressionAnalysis.getResultSets().addAll(thawed);
    // they are the same objects, just updated.
    assert !changed;
    return differentialExpressionAnalysis;
}
Also used : StopWatch(org.apache.commons.lang3.time.StopWatch) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) HashSet(java.util.HashSet)

Example 17 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class ExpressionDataFileServiceImpl method analysisResultSetsToString.

@Override
public void analysisResultSetsToString(Collection<ExpressionAnalysisResultSet> results, Map<Long, String[]> geneAnnotations, StringBuilder buf) {
    Map<Long, StringBuilder> probe2String = new HashMap<>();
    List<DifferentialExpressionAnalysisResult> sortedFirstColumnOfResults = null;
    for (ExpressionAnalysisResultSet ears : results) {
        sortedFirstColumnOfResults = this.analysisResultSetToString(ears, geneAnnotations, buf, probe2String, sortedFirstColumnOfResults);
    }
    // ears loop
    buf.append("\n");
    if (sortedFirstColumnOfResults == null) {
        throw new IllegalStateException("No results for ");
    }
    // Dump the probe data in the sorted order of the 1st column that we originally sorted
    for (DifferentialExpressionAnalysisResult sortedResult : sortedFirstColumnOfResults) {
        CompositeSequence cs = sortedResult.getProbe();
        StringBuilder sb = probe2String.get(cs.getId());
        if (sb == null) {
            ExpressionDataFileServiceImpl.log.warn("Unable to find element " + cs.getId() + " in map");
            break;
        }
        buf.append(sb);
        buf.append("\n");
    }
}
Also used : DifferentialExpressionAnalysisResult(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 18 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class ExpressionDataFileServiceImpl method writeDiffExArchiveFile.

@Override
public void writeDiffExArchiveFile(BioAssaySet experimentAnalyzed, DifferentialExpressionAnalysis analysis, DifferentialExpressionAnalysisConfig config) throws IOException {
    Collection<ArrayDesign> arrayDesigns = this.expressionExperimentService.getArrayDesignsUsed(experimentAnalyzed);
    Map<Long, String[]> geneAnnotations = this.getGeneAnnotationsAsStrings(arrayDesigns);
    String filename = this.getDiffExArchiveFileName(analysis);
    File f = this.getOutputFile(filename);
    ExpressionDataFileServiceImpl.log.info("Creating differential expression analysis archive file: " + f.getName());
    try (ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(f))) {
        // top-level analysis results - ANOVA-style
        zipOut.putNextEntry(new ZipEntry("analysis.results.txt"));
        String analysisData = this.convertDiffExpressionAnalysisData(analysis, geneAnnotations, config);
        zipOut.write(analysisData.getBytes());
        zipOut.closeEntry();
        differentialExpressionAnalysisService.thaw(analysis);
        // Add a file for each result set with contrasts information.
        int i = 0;
        for (ExpressionAnalysisResultSet resultSet : analysis.getResultSets()) {
            if (resultSet.getExperimentalFactors().size() > 1) {
                // Skip interactions.
                // Why?
                ExpressionDataFileServiceImpl.log.info("Result file for interaction is omitted");
                continue;
            }
            String resultSetData = this.convertDiffExpressionResultSetData(resultSet, geneAnnotations, config);
            if (resultSet.getId() == null) {
                // -nodb option on analysis
                zipOut.putNextEntry(new ZipEntry("resultset_" + ++i + "of" + analysis.getResultSets().size() + // to make it clearer this is not an ID
                ".data.txt"));
            } else {
                zipOut.putNextEntry(new ZipEntry("resultset_ID" + resultSet.getId() + ".data.txt"));
            }
            zipOut.write(resultSetData.getBytes());
            zipOut.closeEntry();
        }
    }
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ZipOutputStream(java.util.zip.ZipOutputStream) ZipEntry(java.util.zip.ZipEntry) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)

Example 19 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class SubsettedAnalysis3Test method test.

@Test
public void test() {
    ee = expressionExperimentService.thawLite(ee);
    Collection<ExperimentalFactor> factors = ee.getExperimentalDesign().getExperimentalFactors();
    assertEquals(3, factors.size());
    for (BioAssay ba : ee.getBioAssays()) {
        assertEquals(3, ba.getSampleUsed().getFactorValues().size());
    }
    ExperimentalFactor organismpart = null;
    ExperimentalFactor disease = null;
    ExperimentalFactor diseasegroup = null;
    for (ExperimentalFactor ef : factors) {
        switch(ef.getCategory().getValue()) {
            case "study design":
                diseasegroup = ef;
                break;
            case "disease":
                disease = ef;
                break;
            case "organism part":
                organismpart = ef;
                break;
        }
    }
    assertNotNull(diseasegroup);
    assertNotNull(disease);
    assertNotNull(organismpart);
    DifferentialExpressionAnalysisConfig config = new DifferentialExpressionAnalysisConfig();
    config.getFactorsToInclude().add(disease);
    config.getFactorsToInclude().add(organismpart);
    config.setSubsetFactor(diseasegroup);
    Collection<DifferentialExpressionAnalysis> analyses = analyzer.run(ee, config);
    // a subset for each disease: SZ, PD, HD, ALS, ALZ, MS
    assertEquals(6, analyses.size());
    /*
         * Now, within each we should have only one disease contrast,
         */
    for (DifferentialExpressionAnalysis analysis : analyses) {
        // there should be one for disease - tissue isn't used.
        assertEquals(1, analysis.getResultSets().size());
        for (ExpressionAnalysisResultSet rs : analysis.getResultSets()) {
            ExperimentalFactor factor = rs.getExperimentalFactors().iterator().next();
            // noinspection LoopStatementThatDoesntLoop
            for (DifferentialExpressionAnalysisResult res : rs.getResults()) {
                Collection<ContrastResult> contrasts = res.getContrasts();
                for (ContrastResult cr : contrasts) {
                    log.info(analysis + "   " + factor + " " + cr + " " + res);
                }
                break;
            }
        }
    }
}
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) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) ContrastResult(ubic.gemma.model.analysis.expression.diff.ContrastResult) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Example 20 with ExpressionAnalysisResultSet

use of ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet in project Gemma by PavlidisLab.

the class ProcessedExpressionDataVectorServiceImpl method getDiffExVectors.

@Override
public List<DoubleVectorValueObject> getDiffExVectors(Long resultSetId, Double threshold, int maxNumberOfResults) {
    ExpressionAnalysisResultSet ar = differentialExpressionResultService.loadAnalysisResultSet(resultSetId);
    if (ar == null) {
        Log.warn(this.getClass(), "No diff ex result set with ID=" + resultSetId);
        return null;
    }
    differentialExpressionResultService.thawLite(ar);
    BioAssaySet analyzedSet = ar.getAnalysis().getExperimentAnalyzed();
    List<DifferentialExpressionValueObject> ee2probeResults = differentialExpressionResultService.findInResultSet(ar, threshold, maxNumberOfResults, ProcessedExpressionDataVectorServiceImpl.DIFFEX_MIN_NUMBER_OF_RESULTS);
    Collection<Long> probes = new HashSet<>();
    // Map<CompositeSequenceId, pValue>
    // using id instead of entity for map key because want to use a value object for retrieval later
    Map<Long, Double> pvalues = new HashMap<>();
    for (DifferentialExpressionValueObject par : ee2probeResults) {
        probes.add(par.getProbeId());
        pvalues.put(par.getProbeId(), par.getP());
    }
    Collection<DoubleVectorValueObject> processedDataArraysByProbe = this.getProcessedDataArraysByProbeIds(analyzedSet, probes);
    List<DoubleVectorValueObject> dedvs = new ArrayList<>(processedDataArraysByProbe);
    /*
         * Resort
         */
    for (DoubleVectorValueObject v : dedvs) {
        v.setPvalue(pvalues.get(v.getDesignElement().getId()));
    }
    Collections.sort(dedvs, new Comparator<DoubleVectorValueObject>() {

        @Override
        public int compare(DoubleVectorValueObject o1, DoubleVectorValueObject o2) {
            if (o1.getPvalue() == null)
                return -1;
            if (o2.getPvalue() == null)
                return 1;
            return o1.getPvalue().compareTo(o2.getPvalue());
        }
    });
    return dedvs;
}
Also used : DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) ExpressionAnalysisResultSet(ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Aggregations

ExpressionAnalysisResultSet (ubic.gemma.model.analysis.expression.diff.ExpressionAnalysisResultSet)30 DifferentialExpressionAnalysis (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysis)21 Test (org.junit.Test)17 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)16 DifferentialExpressionAnalysisResult (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionAnalysisResult)14 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)8 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)5 ContrastResult (ubic.gemma.model.analysis.expression.diff.ContrastResult)5 StopWatch (org.apache.commons.lang3.time.StopWatch)4 HashSet (java.util.HashSet)3 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)3 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)3 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 DoubleMatrixReader (ubic.basecode.io.reader.DoubleMatrixReader)2 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)2 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)2 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)2 File (java.io.File)1