Search in sources :

Example 11 with GeneValueObject

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;
}
Also used : VisualizationValueObject(ubic.gemma.web.controller.visualization.VisualizationValueObject) DifferentialExpressionValueObject(ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject) StopWatch(org.apache.commons.lang3.time.StopWatch) GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 12 with GeneValueObject

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();
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)

Example 13 with GeneValueObject

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;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) DifferentialExpressionSearchTaskCommand(ubic.gemma.core.tasks.visualization.DifferentialExpressionSearchTaskCommand)

Example 14 with GeneValueObject

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);
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with GeneValueObject

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;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) StopWatch(org.apache.commons.lang3.time.StopWatch) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)31 StopWatch (org.apache.commons.lang3.time.StopWatch)6 Gene (ubic.gemma.model.genome.Gene)6 Taxon (ubic.gemma.model.genome.Taxon)5 DoubleVectorValueObject (ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject)4 GeneSetValueObject (ubic.gemma.model.genome.gene.GeneSetValueObject)4 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 GeneProductValueObject (ubic.gemma.model.genome.gene.GeneProductValueObject)3 HashSet (java.util.HashSet)2 OntologyTerm (ubic.basecode.ontology.model.OntologyTerm)2 DifferentialExpressionValueObject (ubic.gemma.model.analysis.expression.diff.DifferentialExpressionValueObject)2 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)2 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)2 EvidenceValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.EvidenceValueObject)2 CoexpressionValueObject (ubic.gemma.persistence.service.association.coexpression.CoexpressionValueObject)2 VisualizationValueObject (ubic.gemma.web.controller.visualization.VisualizationValueObject)2 ImageValueObject (ubic.gemma.web.image.aba.ImageValueObject)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1