use of ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix in project Gemma by PavlidisLab.
the class ExpressionExperimentBatchCorrectionServiceImpl method comBat.
@Override
public ExpressionDataDoubleMatrix comBat(ExpressionExperiment ee) {
/*
* is there a batch to use?
*/
ExperimentalFactor batch = this.getBatchFactor(ee);
if (batch == null) {
ExpressionExperimentBatchCorrectionServiceImpl.log.warn("No batch factor found");
return null;
}
/*
* Extract data
*/
Collection<ProcessedExpressionDataVector> vectos = processedExpressionDataVectorService.getProcessedDataVectors(ee);
processedExpressionDataVectorService.thaw(vectos);
ExpressionDataDoubleMatrix mat = new ExpressionDataDoubleMatrix(vectos);
return this.comBat(mat);
}
use of ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix in project Gemma by PavlidisLab.
the class AffyProbeNameFilter method filter.
@Override
public ExpressionDataDoubleMatrix filter(ExpressionDataDoubleMatrix data) {
int numRows = data.rows();
List<CompositeSequence> kept = new ArrayList<>();
for (int i = 0; i < numRows; i++) {
CompositeSequence d = data.getDesignElementForRow(i);
assert d != null;
BioSequence sequence = d.getBiologicalCharacteristic();
String name;
if (sequence != null) {
name = sequence.getName();
} else {
name = d.getName();
}
// apply the rules.
if (skip_ST && name.contains("_st")) {
// 'st' means sense strand.
continue;
}
// control probes.
if (skip_AFFX && name.contains("AFFX")) {
continue;
}
// gene family.
if (skip_F && name.contains("_f_at")) {
continue;
}
if (skip_X && name.contains("_x_at")) {
continue;
}
if (skip_G && name.contains("_g_at")) {
continue;
}
kept.add(d);
}
AffyProbeNameFilter.log.info("There are " + kept.size() + " rows left after Affy probe name filtering.");
return new ExpressionDataDoubleMatrix(data, kept);
}
use of ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix in project Gemma by PavlidisLab.
the class RowLevelFilter method filter.
@Override
public ExpressionDataDoubleMatrix filter(ExpressionDataDoubleMatrix data) {
if (lowCut == -Double.MAX_VALUE && highCut == Double.MAX_VALUE) {
RowLevelFilter.log.info("No filtering requested");
return data;
}
int numRows = data.rows();
DoubleArrayList criteria = new DoubleArrayList(new double[numRows]);
int numAllNeg = this.computeCriteria(data, criteria);
DoubleArrayList sortedCriteria = criteria.copy();
sortedCriteria.sort();
int consideredRows = numRows;
int startIndex = 0;
if (removeAllNegative) {
consideredRows = numRows - numAllNeg;
startIndex = numAllNeg;
}
double realHighCut = this.getHighThreshold(sortedCriteria, consideredRows);
double realLowCut = this.getLowThreshold(numRows, sortedCriteria, consideredRows, startIndex);
if (Double.isNaN(realHighCut)) {
throw new IllegalStateException("High threshold cut is NaN");
}
RowLevelFilter.log.debug("Low cut = " + realLowCut);
RowLevelFilter.log.debug("High cut = " + realHighCut);
if (realHighCut <= realLowCut) {
throw new RuntimeException("High cut " + realHighCut + " is lower or same as low cut " + realLowCut);
}
List<CompositeSequence> kept = new ArrayList<>();
for (int i = 0; i < numRows; i++) {
// values, zeros should always be removed
if (criteria.get(i) > realLowCut && criteria.get(i) <= realHighCut) {
kept.add(data.getDesignElementForRow(i));
}
}
this.logInfo(numRows, kept);
return new ExpressionDataDoubleMatrix(data, kept);
}
use of ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix in project Gemma by PavlidisLab.
the class SVDServiceHelperImpl method svd.
@Override
public SVDValueObject svd(ExpressionExperiment ee) {
assert ee != null;
Collection<ProcessedExpressionDataVector> vectors = processedExpressionDataVectorService.getProcessedDataVectors(ee);
if (vectors.isEmpty()) {
throw new IllegalArgumentException("Experiment must have processed data already to do SVD");
}
processedExpressionDataVectorService.thaw(vectors);
ExpressionDataDoubleMatrix mat = new ExpressionDataDoubleMatrix(vectors);
SVDServiceHelperImpl.log.info("Starting SVD");
ExpressionDataSVD svd = new ExpressionDataSVD(mat);
SVDServiceHelperImpl.log.info("SVD done, postprocessing and storing results.");
/*
* Save the results
*/
DoubleMatrix<Integer, BioMaterial> v = svd.getV();
BioAssayDimension b = mat.getBestBioAssayDimension();
PrincipalComponentAnalysis pca = this.updatePca(ee, svd, v, b);
return this.svdFactorAnalysis(pca);
}
use of ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix in project Gemma by PavlidisLab.
the class ExpressionDataSVDTest method testMatrixReconstruct.
@Test
public void testMatrixReconstruct() {
ExpressionDataDoubleMatrix svdNormalize = svd.removeHighestComponents(0);
assertNotNull(svdNormalize);
RegressionTesting.closeEnough(testData.getMatrix(), svdNormalize.getMatrix(), 0.001);
}
Aggregations