use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.
the class DEDVController method handleRequestInternal.
/**
* Handle case of text export of the results.
*/
@RequestMapping("/downloadDEDV.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> eeIds = ControllerUtils.extractIds(request.getParameter("ee"));
ModelAndView mav = new ModelAndView(new TextView());
if (eeIds == null || eeIds.isEmpty()) {
mav.addObject("text", "Input empty for finding DEDVs: " + geneIds + " and " + eeIds);
return mav;
}
String threshSt = request.getParameter("thresh");
String resultSetIdSt = request.getParameter("rs");
Double thresh = 100.0;
if (StringUtils.isNotBlank(threshSt)) {
try {
thresh = Double.parseDouble(threshSt);
} catch (NumberFormatException e) {
throw new RuntimeException("Threshold was not a valid value: " + threshSt);
}
}
Map<ExpressionExperimentValueObject, Map<Long, Collection<DoubleVectorValueObject>>> result;
if (request.getParameter("pca") != null) {
int component = Integer.parseInt(request.getParameter("component"));
Long eeId = eeIds.iterator().next();
Map<ProbeLoading, DoubleVectorValueObject> topLoadedVectors = this.svdService.getTopLoadedVectors(eeId, component, thresh.intValue());
if (topLoadedVectors == null)
return null;
mav.addObject("text", format4File(topLoadedVectors.values()));
return mav;
}
/*
* The following should be set if we're viewing diff. ex results.
*/
Long resultSetId = null;
if (StringUtils.isNumeric(resultSetIdSt)) {
resultSetId = Long.parseLong(resultSetIdSt);
}
if (resultSetId != null) {
/*
* Diff ex case.
*/
Long eeId = eeIds.iterator().next();
Collection<DoubleVectorValueObject> diffExVectors = processedExpressionDataVectorService.getDiffExVectors(resultSetId, thresh, MAX_RESULTS_TO_RETURN);
if (diffExVectors == null || diffExVectors.isEmpty()) {
mav.addObject("text", "No results");
return mav;
}
/*
* Organize the vectors in the same way expected by the ee+gene type of request.
*/
ExpressionExperimentValueObject ee = expressionExperimentService.loadValueObject(expressionExperimentService.load(eeId));
result = new HashMap<>();
Map<Long, Collection<DoubleVectorValueObject>> gmap = new HashMap<>();
for (DoubleVectorValueObject dv : diffExVectors) {
for (Long g : dv.getGenes()) {
if (!gmap.containsKey(g)) {
gmap.put(g, new HashSet<DoubleVectorValueObject>());
}
gmap.get(g).add(dv);
}
}
result.put(ee, gmap);
} else {
// Generic listing.
result = getDEDV(eeIds, geneIds);
}
if (result == null || result.isEmpty()) {
mav.addObject("text", "No results");
return mav;
}
mav.addObject("text", format4File(result));
watch.stop();
Long time = watch.getTime();
if (time > 100) {
log.info("Retrieved and Formated" + result.keySet().size() + " DEDVs for eeIDs: " + eeIds + " and GeneIds: " + geneIds + " in : " + time + " ms.");
}
return mav;
}
use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.
the class ExpressionExperimentQCController method identifyPossibleOutliers.
@RequestMapping("/expressionExperiment/possibleOutliers.html")
public ModelAndView identifyPossibleOutliers(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;
}
// identify outliers
if (!sampleCoexpressionMatrixService.hasMatrix(ee)) {
log.warn("Experiment doesn't have correlation matrix computed (will not create right now)");
return null;
}
DoubleMatrix<BioAssay, BioAssay> sampleCorrelationMatrix = sampleCoexpressionMatrixService.findOrCreate(ee);
Collection<OutlierDetails> outliers = outlierDetectionService.identifyOutliersByMedianCorrelation(ee);
Collection<BioAssay> bioAssays = new HashSet<>();
if (!outliers.isEmpty()) {
for (OutlierDetails details : outliers) {
bioAssays.add(details.getBioAssay());
}
}
// and write it out
StringWriter writer = new StringWriter();
StringBuffer buf = writer.getBuffer();
ExpressionDataWriterUtils.appendBaseHeader(ee, "Sample outlier", 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 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;
}
use of ubic.gemma.web.view.TextView 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;
}
use of ubic.gemma.web.view.TextView in project Gemma by PavlidisLab.
the class BlatResultTrackController method handleRequestInternal.
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) {
String idS = request.getParameter("id");
Long id = null;
try {
id = Long.parseLong(idS);
} catch (NumberFormatException e) {
// return error view.
}
Collection<Long> ids = new HashSet<Long>();
ids.add(id);
Collection<BlatResult> res = blatResultService.load(ids);
if (res.size() == 0) {
// should be an error.
}
assert res.size() == 1;
BlatResult toView = res.iterator().next();
toView = blatResultService.thaw(toView);
String val = BlatResult2Psl.blatResult2PslTrack(toView);
return new ModelAndView(new TextView(), "text", val);
}
Aggregations