Search in sources :

Example 1 with TextView

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;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) ProbeLoading(ubic.gemma.model.analysis.expression.pca.ProbeLoading) StopWatch(org.apache.commons.lang3.time.StopWatch) TextView(ubic.gemma.web.view.TextView) DoubleVectorValueObject(ubic.gemma.model.expression.bioAssayData.DoubleVectorValueObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TextView

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;
}
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) OutlierDetails(ubic.gemma.core.analysis.preprocess.OutlierDetails) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with TextView

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;
}
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 4 with TextView

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

Example 5 with TextView

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);
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) HashSet(java.util.HashSet) BlatResult(ubic.gemma.model.genome.sequenceAnalysis.BlatResult)

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