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;
}
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");
}
}
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();
}
}
}
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;
}
}
}
}
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;
}
Aggregations