use of ubic.gemma.model.genome.gene.GeneValueObject 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.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class DEDVController method format4File.
private String format4File(Collection<DoubleVectorValueObject> vectors) {
StringBuilder converted = new StringBuilder();
converted.append("# Generated by Gemma\n# ").append(new Date()).append("\n");
converted.append(ExpressionDataFileService.DISCLAIMER + "#\n");
boolean didHeader = false;
Map<Long, GeneValueObject> gmap = getGeneValueObjectsUsed(vectors);
for (DoubleVectorValueObject vec : vectors) {
if (!didHeader) {
converted.append(makeHeader(vec));
didHeader = true;
}
List<String> geneSymbols = new ArrayList<>();
List<String> geneNames = new ArrayList<>();
for (Long g : vec.getGenes()) {
GeneValueObject gene = gmap.get(g);
assert gene != null;
geneSymbols.add(gene.getOfficialSymbol());
geneNames.add(gene.getOfficialName());
}
converted.append(StringUtils.join(geneSymbols, "|")).append("\t").append(StringUtils.join(geneNames, "|")).append("\t");
converted.append(vec.getDesignElement().getName()).append("\t");
if (vec.getData() != null || vec.getData().length != 0) {
for (double data : vec.getData()) {
converted.append(String.format("%.3f", data)).append("\t");
}
// remove the trailing tab // FIXME just joind
converted.deleteCharAt(converted.length() - 1);
}
converted.append("\n");
}
return converted.toString();
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class DifferentialExpressionSearchController method scheduleDiffExpSearchTask.
/**
* AJAX - method used for main display metaheatmap.
*/
// used in js DiffExSearchAndVisualize
@SuppressWarnings("unused")
public String scheduleDiffExpSearchTask(Long taxonId, ExpressionExperimentSetValueObject eevo, GeneSetValueObject gsvo) {
log.info("Starting gene x condition search...");
// Load experiments
Collection<ExpressionExperimentValueObject> experiments;
List<String> datasetGroupNames = new ArrayList<>();
if (eevo.getExpressionExperimentIds().isEmpty()) {
if (eevo.getId() != null) {
experiments = expressionExperimentSetService.getExperimentValueObjectsInSet(eevo.getId());
} else if (eevo.getName() != null) {
Collection<ExpressionExperimentSet> eesets = expressionExperimentSetService.findByName(eevo.getName());
if (eesets.isEmpty() || eesets.size() > 1) {
throw new IllegalArgumentException("Experiment set not found by name=" + eevo.getName());
}
experiments = expressionExperimentSetService.getExperimentValueObjectsInSet(eesets.iterator().next().getId());
} else {
throw new IllegalArgumentException("Experiment group should either have an id or a list of ee ids, or a unique name");
}
} else {
experiments = loadExperimentsByIds(eevo.getExpressionExperimentIds());
}
datasetGroupNames.add(eevo.getName());
// Load genes
Collection<GeneValueObject> genes;
if (gsvo.getGeneIds().isEmpty()) {
genes = geneSetService.getGenesInGroup(gsvo);
} else {
genes = geneService.loadValueObjectsByIds(gsvo.getGeneIds());
}
log.info("Got genes");
// FIXME why not just pass in the eeset and geneset (security filtering could happen there)
final DifferentialExpressionSearchTaskCommand taskCommand = new DifferentialExpressionSearchTaskCommand(genes, experiments, gsvo.getName(), eevo.getName());
String taskId = taskRunningService.submitLocalTask(taskCommand);
log.info("Scheduled search with task=" + taskId);
return taskId;
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneController method showMultiple.
/**
* @return ModelAndView
*/
@RequestMapping(value = { "/showGenes.html", "/show.html" }, method = RequestMethod.GET)
public ModelAndView showMultiple(HttpServletRequest request, HttpServletResponse response) {
String sId = request.getParameter("id");
Collection<GeneValueObject> genes = new ArrayList<>();
// if no IDs are specified, then show an error message
if (sId == null) {
addMessage(request, "object.notfound", new Object[] { "All genes cannot be listed. Genes " });
} else // if ids are specified, then display only those genes
{
String[] idList = StringUtils.split(sId, ',');
for (String anIdList : idList) {
Long id = Long.parseLong(anIdList);
GeneValueObject gene = geneService.loadValueObjectById(id);
if (gene == null) {
addMessage(request, "object.notfound", new Object[] { "Gene " + id });
}
genes.add(gene);
}
}
/*
* FIXME this view doesn't exist!
*/
return new ModelAndView("genes").addObject("genes", genes);
}
use of ubic.gemma.model.genome.gene.GeneValueObject in project Gemma by PavlidisLab.
the class GeneController method handleRequestInternal.
@RequestMapping("/downloadGeneList.html")
protected ModelAndView handleRequestInternal(HttpServletRequest request) {
StopWatch watch = new StopWatch();
watch.start();
// might not be any
Collection<Long> geneIds = ControllerUtils.extractIds(request.getParameter("g"));
// might not be there
Collection<Long> geneSetIds = ControllerUtils.extractIds(request.getParameter("gs"));
// might not be there
String geneSetName = request.getParameter("gsn");
ModelAndView mav = new ModelAndView(new TextView());
if ((geneIds == null || geneIds.isEmpty()) && (geneSetIds == null || geneSetIds.isEmpty())) {
mav.addObject("text", "Could not find genes to match gene ids: {" + geneIds + "} or gene set ids {" + geneSetIds + "}");
return mav;
}
Collection<GeneValueObject> genes = new ArrayList<>();
if (geneIds != null) {
for (Long id : geneIds) {
genes.add(geneService.loadValueObjectById(id));
}
}
if (geneSetIds != null) {
for (Long id : geneSetIds) {
genes.addAll(geneSetService.getGenesInGroup(new GeneSetValueObject(id)));
}
}
mav.addObject("text", format4File(genes, geneSetName));
watch.stop();
Long time = watch.getTime();
if (time > 100) {
log.info("Retrieved and Formated" + genes.size() + " genes in : " + time + " ms.");
}
return mav;
}
Aggregations