Search in sources :

Example 6 with TextView

use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method identifyOutliersRemoved.

@RequestMapping("/expressionExperiment/outliersRemoved.html")
public ModelAndView identifyOutliersRemoved(Long id) throws IOException {
    if (id == null) {
        log.warn("No id!");
        return null;
    }
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        log.warn("Could not load experiment with id " + id);
        return null;
    }
    ee = expressionExperimentService.thawLite(ee);
    Collection<BioAssay> bioAssays = new HashSet<>();
    for (BioAssay assay : ee.getBioAssays()) {
        if (assay.getIsOutlier()) {
            bioAssays.add(assay);
        }
    }
    // and write it out
    StringWriter writer = new StringWriter();
    StringBuffer buf = writer.getBuffer();
    ExpressionDataWriterUtils.appendBaseHeader(ee, "Outliers removed", buf);
    ExperimentalDesignWriter edWriter = new ExperimentalDesignWriter();
    ee = expressionExperimentService.thawLiter(ee);
    edWriter.write(writer, ee, bioAssays, false, true);
    ModelAndView mav = new ModelAndView(new TextView());
    mav.addObject(TextView.TEXT_PARAM, buf.toString());
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) ExperimentalDesignWriter(ubic.gemma.core.datastructure.matrix.ExperimentalDesignWriter) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with TextView

use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method visualizeCorrMat.

/**
 * @param id         of experiment
 * @param size       Multiplier on the cell size. 1 or null for standard small size.
 * @param text       if true, output a tabbed file instead of a png
 * @param showLabels if the row and column labels of the matrix should be shown.
 * @param os         response output stream
 */
@RequestMapping("/expressionExperiment/visualizeCorrMat.html")
public ModelAndView visualizeCorrMat(Long id, Double size, String contrVal, Boolean text, Boolean showLabels, Boolean forceShowLabels, OutputStream os) throws Exception {
    if (id == null) {
        log.warn("No id!");
        return null;
    }
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        log.warn("Could not load experiment with id " + id);
        return null;
    }
    DoubleMatrix<BioAssay, BioAssay> omatrix = sampleCoexpressionMatrixService.findOrCreate(ee);
    List<String> stringNames = new ArrayList<>();
    for (BioAssay ba : omatrix.getRowNames()) {
        stringNames.add(ba.getName() + " ID=" + ba.getId());
    }
    DoubleMatrix<String, String> matrix = new DenseDoubleMatrix<>(omatrix.getRawMatrix());
    matrix.setRowNames(stringNames);
    matrix.setColumnNames(stringNames);
    if (text != null && text) {
        StringWriter s = new StringWriter();
        MatrixWriter<String, String> mw = new MatrixWriter<>(s, new DecimalFormat("#.##"));
        mw.writeMatrix(matrix, true);
        ModelAndView mav = new ModelAndView(new TextView());
        mav.addObject(TextView.TEXT_PARAM, s.toString());
        return mav;
    }
    /*
         * Blank out the diagonal so it doesn't affect the colour scale.
         */
    for (int i = 0; i < matrix.rows(); i++) {
        matrix.set(i, i, Double.NaN);
    }
    ColorMatrix<String, String> cm = new ColorMatrix<>(matrix);
    this.cleanNames(matrix);
    int row = matrix.rows();
    int cellsize = (int) Math.min(ExpressionExperimentQCController.MAX_HEATMAP_CELLSIZE, Math.max(1, size * ExpressionExperimentQCController.DEFAULT_QC_IMAGE_SIZE_PX / row));
    MatrixDisplay<String, String> writer = new MatrixDisplay<>(cm);
    boolean reallyShowLabels;
    int minimumCellSizeForText = 9;
    if (forceShowLabels != null && forceShowLabels) {
        cellsize = Math.min(ExpressionExperimentQCController.MAX_HEATMAP_CELLSIZE, minimumCellSizeForText);
        reallyShowLabels = true;
    } else {
        reallyShowLabels = showLabels != null && (showLabels && cellsize >= minimumCellSizeForText);
    }
    writer.setCellSize(new Dimension(cellsize, cellsize));
    boolean showScalebar = size > 2;
    writer.writeToPng(cm, os, reallyShowLabels, showScalebar);
    // nothing to return;
    return null;
}
Also used : DecimalFormat(java.text.DecimalFormat) DoubleArrayList(cern.colt.list.DoubleArrayList) ModelAndView(org.springframework.web.servlet.ModelAndView) ColorMatrix(ubic.basecode.graphics.ColorMatrix) MatrixDisplay(ubic.basecode.graphics.MatrixDisplay) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) TextView(ubic.gemma.web.view.TextView) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) MatrixWriter(ubic.basecode.io.writer.MatrixWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with TextView

use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method visualizeMeanVariance.

/**
 * @param id   of experiment
 * @param size Multiplier on the cell size. 1 or null for standard small size.
 * @param text if true, output a tabbed file instead of a png
 * @param os   response output stream
 * @return ModelAndView object if text is true, otherwise null
 */
@RequestMapping("/expressionExperiment/visualizeMeanVariance.html")
public ModelAndView visualizeMeanVariance(Long id, Double size, Boolean text, OutputStream os) throws Exception {
    if (id == null) {
        log.warn("No id!");
        return null;
    }
    ExpressionExperiment ee = expressionExperimentService.load(id);
    if (ee == null) {
        log.warn("Could not load experiment with id " + id);
        return null;
    }
    MeanVarianceRelation mvr = meanVarianceService.find(ee);
    if (mvr == null) {
        return null;
    }
    if (text != null && text) {
        final ByteArrayConverter bac = new ByteArrayConverter();
        double[] means = bac.byteArrayToDoubles(mvr.getMeans());
        double[] variances = bac.byteArrayToDoubles(mvr.getVariances());
        DoubleMatrix2D matrix = new DenseDoubleMatrix2D(means.length, 2);
        matrix.viewColumn(0).assign(means);
        matrix.viewColumn(1).assign(variances);
        String matrixString = new Formatter("%1.2G").toTitleString(matrix, null, new String[] { "mean", "variance" }, null, null, null, null);
        ModelAndView mav = new ModelAndView(new TextView());
        mav.addObject(TextView.TEXT_PARAM, matrixString);
        return mav;
    }
    this.writeMeanVariance(os, mvr, size);
    return null;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) DoubleMatrix2D(cern.colt.matrix.DoubleMatrix2D) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) Formatter(cern.colt.matrix.doublealgo.Formatter) ModelAndView(org.springframework.web.servlet.ModelAndView) MeanVarianceRelation(ubic.gemma.model.expression.bioAssayData.MeanVarianceRelation) TextView(ubic.gemma.web.view.TextView) DenseDoubleMatrix2D(cern.colt.matrix.impl.DenseDoubleMatrix2D) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with TextView

use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.

the class ExpressionExperimentController method handleRequestInternal.

@RequestMapping("/downloadExpressionExperimentList.html")
protected ModelAndView handleRequestInternal(HttpServletRequest request) {
    StopWatch watch = new StopWatch();
    watch.start();
    // might not be any
    Collection<Long> eeIds = ControllerUtils.extractIds(request.getParameter("e"));
    // might not be there
    Collection<Long> eeSetIds = ControllerUtils.extractIds(request.getParameter("es"));
    // might not be there
    String eeSetName = request.getParameter("esn");
    ModelAndView mav = new ModelAndView(new TextView());
    if ((eeIds == null || eeIds.isEmpty()) && (eeSetIds == null || eeSetIds.isEmpty())) {
        mav.addObject(TextView.TEXT_PARAM, "Could not find genes to match expression experiment ids: {" + eeIds + "} or expression experiment set ids {" + eeSetIds + "}");
        return mav;
    }
    Collection<ExpressionExperimentValueObject> ees = expressionExperimentService.loadValueObjects(eeIds, false);
    for (Long id : eeSetIds) {
        ees.addAll(expressionExperimentSetService.getExperimentValueObjectsInSet(id));
    }
    mav.addObject(TextView.TEXT_PARAM, this.format4File(ees, eeSetName));
    watch.stop();
    Long time = watch.getTime();
    if (time > 100) {
        ExpressionExperimentController.log.info("Retrieved and Formated" + ees.size() + " genes in : " + time + " ms.");
    }
    return mav;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) StopWatch(org.apache.commons.lang3.time.StopWatch) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ModelAndView (org.springframework.web.servlet.ModelAndView)9 TextView (ubic.gemma.web.view.TextView)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)5 StopWatch (org.apache.commons.lang3.time.StopWatch)3 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)3 DecimalFormat (java.text.DecimalFormat)2 MatrixWriter (ubic.basecode.io.writer.MatrixWriter)2 ExperimentalDesignWriter (ubic.gemma.core.datastructure.matrix.ExperimentalDesignWriter)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 DoubleMatrix2D (cern.colt.matrix.DoubleMatrix2D)1 Formatter (cern.colt.matrix.doublealgo.Formatter)1 DenseDoubleMatrix2D (cern.colt.matrix.impl.DenseDoubleMatrix2D)1 HashSet (java.util.HashSet)1 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)1 ColorMatrix (ubic.basecode.graphics.ColorMatrix)1 MatrixDisplay (ubic.basecode.graphics.MatrixDisplay)1 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)1 OutlierDetails (ubic.gemma.core.analysis.preprocess.OutlierDetails)1 SVDValueObject (ubic.gemma.core.analysis.preprocess.svd.SVDValueObject)1