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