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;
}
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;
}
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;
}
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;
}
Aggregations