use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.
the class DEDVController method makeDiffVisCollection.
/**
* Takes the DEDVs and put them in point objects and normalize the values. returns a map of eeid to visValueObject.
* Currently removes multiple hits for same gene. Tries to pick best DEDV. Organizes the experiments from lowest to
* higest p-value
*
* @param validatedProbes (bad name)
*/
private VisualizationValueObject[] makeDiffVisCollection(Collection<DoubleVectorValueObject> dedvs, List<Long> genes, Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes, Map<Long, LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>>> layouts) {
StopWatch watch = new StopWatch();
watch.start();
Map<Long, Collection<DoubleVectorValueObject>> vvoMap = new HashMap<>();
Map<Long, ExpressionExperimentValueObject> eeMap = new HashMap<>();
// Organize by expression experiment
for (DoubleVectorValueObject dvvo : dedvs) {
ExpressionExperimentValueObject ee = dvvo.getExpressionExperiment();
eeMap.put(ee.getId(), ee);
if (!vvoMap.containsKey(ee.getId())) {
vvoMap.put(ee.getId(), new HashSet<DoubleVectorValueObject>());
}
vvoMap.get(ee.getId()).add(dvvo);
}
class EE2PValue implements Comparable<EE2PValue> {
Long EEId;
double pValue;
public EE2PValue() {
super();
}
public EE2PValue(Long eeid, double pValue) {
this();
this.EEId = eeid;
this.pValue = pValue;
}
@Override
public int compareTo(EE2PValue o) {
if (this.pValue > o.getPValue())
return 1;
else if (this.pValue > o.getPValue())
return -1;
else
return 0;
}
public Long getEEId() {
return EEId;
}
public double getPValue() {
return pValue;
}
}
List<EE2PValue> sortedEE = new ArrayList<>();
// Need to sort the expression experiments by lowest p-value
for (Long eeId : vvoMap.keySet()) {
Collection<DifferentialExpressionValueObject> devos = validatedProbes.get(eeId);
double minP = 1;
if (devos != null && !devos.isEmpty()) {
for (DifferentialExpressionValueObject devo : devos) {
if (minP > devo.getP()) {
minP = devo.getP();
}
}
}
sortedEE.add(new EE2PValue(eeId, minP));
}
Collections.sort(sortedEE);
VisualizationValueObject[] result = new VisualizationValueObject[vvoMap.keySet().size()];
List<GeneValueObject> geneValueObjects = getGeneValueObjectList(genes);
// Create collection of visualizationValueObject for flotr on js side
int i = 0;
for (EE2PValue ee2P : sortedEE) {
VisualizationValueObject vvo = new VisualizationValueObject(vvoMap.get(ee2P.getEEId()), geneValueObjects, ee2P.getPValue(), validatedProbes.get(ee2P.getEEId()));
getSampleNames(vvoMap.get(ee2P.getEEId()), vvo, layouts);
if (layouts != null && !layouts.isEmpty() && layouts.containsKey(ee2P.getEEId())) {
LinkedHashMap<BioAssayValueObject, LinkedHashMap<ExperimentalFactor, Double>> layout = layouts.get(ee2P.getEEId());
this.prepareFactorsForFrontEndDisplay(vvo, layout);
}
if (layouts != null) {
ExpressionExperimentValueObject ee = eeMap.get(ee2P.getEEId());
log.debug("setup experimental design layout profiles for " + ee);
vvo.setUpFactorProfiles(layouts.get(ee.getId()));
}
result[i] = vvo;
i++;
}
Long time = watch.getTime();
if (time > 1000) {
log.info("Created vis value objects in: " + time);
}
return result;
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.
the class DEDVController method getProbeDiffExValidation.
/**
* This is probably no longer being really used?
*/
private Map<Long, Collection<DifferentialExpressionValueObject>> getProbeDiffExValidation(Collection<Gene> genes, Double threshold, Collection<DiffExpressionSelectedFactorCommand> factorMap) {
if (factorMap == null)
throw new IllegalArgumentException("Factor information is missing, please make sure factors are selected.");
Map<Long, Collection<DifferentialExpressionValueObject>> validatedProbes = new HashMap<>();
Collection<Long> wantedFactors = new HashSet<>();
for (DiffExpressionSelectedFactorCommand factor : factorMap) {
wantedFactors.add(factor.getEfId());
}
for (Gene gene : genes) {
Collection<DifferentialExpressionValueObject> differentialExpression = geneDifferentialExpressionService.getDifferentialExpression(gene, threshold, factorMap);
for (DifferentialExpressionValueObject diffVo : differentialExpression) {
assert diffVo.getCorrP() <= threshold;
Long eeId = diffVo.getExpressionExperiment().getId();
if (!validatedProbes.containsKey(eeId)) {
validatedProbes.put(eeId, new HashSet<DifferentialExpressionValueObject>());
}
Collection<ExperimentalFactorValueObject> factors = diffVo.getExperimentalFactors();
for (ExperimentalFactorValueObject fac : factors) {
if (wantedFactors.contains(fac.getId())) {
validatedProbes.get(eeId).add(diffVo);
}
}
}
}
return validatedProbes;
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.
the class DifferentialExpressionSearchController method getDifferentialExpressionWithoutBatch.
/**
* AJAX entry which returns results on a non-meta analysis basis. That is, the differential expression results for
* the gene with the id, geneId, are returned. This method is just like getDifferentialExpression but any analyses
* with the 'batch' factor are filtered out because they are not biologically relevant
*/
public Collection<DifferentialExpressionValueObject> getDifferentialExpressionWithoutBatch(Long geneId, double threshold, Integer limit) {
Collection<DifferentialExpressionValueObject> analyses = getDifferentialExpression(geneId, threshold, limit);
// for each DifferentialExpressionValueObject, check if its factors includes a batch factor and if so, remove
// the batch factor
Collection<DifferentialExpressionValueObject> toRemove = new ArrayList<>();
for (DifferentialExpressionValueObject analysis : analyses) {
for (ExperimentalFactorValueObject factor : analysis.getExperimentalFactors()) {
if (ExperimentalDesignUtils.isBatch(factor)) {
toRemove.add(analysis);
}
}
}
analyses.removeAll(toRemove);
return analyses;
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject 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;
}
use of ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject in project Gemma by PavlidisLab.
the class DifferentialExpressionMetaAnalysisValueObject method toString.
@Override
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append("# MetaP = ").append(this.getFisherPValue()).append("\n");
for (DifferentialExpressionValueObject result : this.getProbeResults()) {
buf.append(result).append("\n");
}
return buf.toString();
}
Aggregations