Search in sources :

Example 1 with OutlierDetails

use of ubic.gemma.core.analysis.preprocess.OutlierDetails in project Gemma by PavlidisLab.

the class LinkAnalysisServiceImpl method qcCheck.

/**
 * Reject if experiment has outliers or batch effects.
 */
private void qcCheck(LinkAnalysisConfig config, ExpressionExperiment ee) throws UnsuitableForAnalysisException {
    if (config.isCheckForOutliers()) {
        Collection<OutlierDetails> outliers = outlierDetectionService.identifyOutliersByMedianCorrelation(ee);
        if (!outliers.isEmpty()) {
            throw new UnsuitableForAnalysisException(ee, "Potential outlier samples detected");
        }
    }
    if (config.isCheckForBatchEffect()) {
        BatchEffectDetails batchEffect = eeService.getBatchEffect(ee);
        if (batchEffect.getDataWasBatchCorrected()) {
            LinkAnalysisServiceImpl.log.info("Data are batch-corrected");
            return;
        }
        if (batchEffect.hasNoBatchInfo()) {
            // we may change this behaviour...
            throw new UnsuitableForAnalysisException(ee, "No batch information available, out of an abundance of caution we are skipping");
        }
        if (batchEffect.getPvalue() < 0.001) {
            double componentVarianceProportion = batchEffect.getComponentVarianceProportion();
            Integer component = batchEffect.getComponent();
            // this far.
            if (component > 2 && componentVarianceProportion < 0.1) {
                return;
            }
            throw new UnsuitableForAnalysisException(ee, String.format("Strong batch effect detected (%s)", batchEffect));
        }
    }
}
Also used : OutlierDetails(ubic.gemma.core.analysis.preprocess.OutlierDetails) BatchEffectDetails(ubic.gemma.core.analysis.preprocess.batcheffects.BatchEffectDetails)

Example 2 with OutlierDetails

use of ubic.gemma.core.analysis.preprocess.OutlierDetails 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 OutlierDetails

use of ubic.gemma.core.analysis.preprocess.OutlierDetails in project Gemma by PavlidisLab.

the class BioAssayController method getBioAssays.

public Collection<BioAssayValueObject> getBioAssays(Long eeId) {
    ExpressionExperiment ee = eeService.load(eeId);
    if (ee == null) {
        throw new IllegalArgumentException("Could not load experiment with ID=" + eeId);
    }
    ee = this.eeService.thawLite(ee);
    Collection<BioAssayValueObject> result = new HashSet<>();
    // this used to be in a separate method.
    DoubleMatrix<BioAssay, BioAssay> sampleCorrelationMatrix = sampleCoexpressionMatrixService.findOrCreate(ee);
    Collection<OutlierDetails> outliers = outlierDetectionService.identifyOutliersByMedianCorrelation(ee);
    Map<Long, OutlierDetails> outlierMap = EntityUtils.getNestedIdMap(outliers, "bioAssay", "getId");
    for (BioAssay assay : ee.getBioAssays()) {
        BioAssayValueObject bioAssayValueObject = new BioAssayValueObject(assay, false);
        if (outlierMap.containsKey(assay.getId())) {
            bioAssayValueObject.setPredictedOutlier(true);
        }
        result.add(bioAssayValueObject);
    }
    BioAssayController.log.debug("Loaded " + result.size() + " bioassays for experiment ID=" + eeId);
    return result;
}
Also used : BioAssayValueObject(ubic.gemma.model.expression.bioAssay.BioAssayValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) OutlierDetails(ubic.gemma.core.analysis.preprocess.OutlierDetails) HashSet(java.util.HashSet)

Aggregations

OutlierDetails (ubic.gemma.core.analysis.preprocess.OutlierDetails)3 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 HashSet (java.util.HashSet)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1 ModelAndView (org.springframework.web.servlet.ModelAndView)1 BatchEffectDetails (ubic.gemma.core.analysis.preprocess.batcheffects.BatchEffectDetails)1 ExperimentalDesignWriter (ubic.gemma.core.datastructure.matrix.ExperimentalDesignWriter)1 BioAssayValueObject (ubic.gemma.model.expression.bioAssay.BioAssayValueObject)1 TextView (ubic.gemma.web.view.TextView)1