Search in sources :

Example 1 with MatrixWriter

use of ubic.basecode.io.writer.MatrixWriter in project Gemma by PavlidisLab.

the class ExpressionExperimentQCController method writeEigenGenes.

@RequestMapping("/expressionExperiment/eigenGenes.html")
public ModelAndView writeEigenGenes(Long eeid) throws IOException {
    ExpressionExperiment ee = expressionExperimentService.load(eeid);
    if (ee == null) {
        // or access deined.
        throw new IllegalArgumentException("Could not load experiment with id " + eeid);
    }
    SVDValueObject svdo = svdService.getSvd(ee.getId());
    DoubleMatrix<Long, Integer> vMatrix = svdo.getvMatrix();
    /*
         * FIXME put the biomaterial names in there instead of the IDs.
         */
    /*
         * new DenseDoubleMatrix<String, String>() DoubleMatrix<String, String> matrix = new DenseDoubleMatrix<String,
         * String>( omatrix.getRawMatrix() ); matrix.setRowNames( stringNames ); matrix.setColumnNames( stringNames );
         */
    StringWriter s = new StringWriter();
    MatrixWriter<Long, Integer> mw = new MatrixWriter<>(s, new DecimalFormat("#.######"));
    mw.writeMatrix(vMatrix, true);
    ModelAndView mav = new ModelAndView(new TextView());
    mav.addObject(TextView.TEXT_PARAM, s.toString());
    return mav;
}
Also used : DecimalFormat(java.text.DecimalFormat) SVDValueObject(ubic.gemma.core.analysis.preprocess.svd.SVDValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) MatrixWriter(ubic.basecode.io.writer.MatrixWriter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with MatrixWriter

use of ubic.basecode.io.writer.MatrixWriter 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)

Aggregations

DecimalFormat (java.text.DecimalFormat)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 MatrixWriter (ubic.basecode.io.writer.MatrixWriter)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 TextView (ubic.gemma.web.view.TextView)2 DoubleArrayList (cern.colt.list.DoubleArrayList)1 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)1 ColorMatrix (ubic.basecode.graphics.ColorMatrix)1 MatrixDisplay (ubic.basecode.graphics.MatrixDisplay)1 SVDValueObject (ubic.gemma.core.analysis.preprocess.svd.SVDValueObject)1 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)1