use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class ExpressionPersister method fillInExpressionExperimentDataVectorAssociations.
private Collection<BioAssay> fillInExpressionExperimentDataVectorAssociations(ExpressionExperiment ee, ArrayDesignsForExperimentCache c) {
AbstractPersister.log.info("Filling in DesignElementDataVectors...");
Collection<BioAssay> bioAssays = new HashSet<>();
StopWatch timer = new StopWatch();
timer.start();
int count = 0;
for (RawExpressionDataVector dataVector : ee.getRawExpressionDataVectors()) {
BioAssayDimension bioAssayDimension = this.fillInDesignElementDataVectorAssociations(dataVector, c);
if (timer.getTime() > 5000) {
if (count == 0) {
AbstractPersister.log.info("Setup: " + timer.getTime());
} else {
AbstractPersister.log.info("Filled in " + (count) + " DesignElementDataVectors (" + timer.getTime() + "ms since last check)");
}
timer.reset();
timer.start();
}
bioAssays.addAll(bioAssayDimension.getBioAssays());
++count;
if (Thread.interrupted()) {
AbstractPersister.log.info("Cancelled");
return null;
}
}
AbstractPersister.log.info("Filled in total of " + count + " DesignElementDataVectors, " + bioAssays.size() + " bioassays");
return bioAssays;
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class ExpressionPersister method fillInDesignElementDataVectorAssociations.
private BioAssayDimension fillInDesignElementDataVectorAssociations(DesignElementDataVector dataVector, ArrayDesignsForExperimentCache c) {
// we should have done this already.
assert dataVector.getDesignElement() != null && !this.isTransient(dataVector.getDesignElement());
BioAssayDimension bioAssayDimension = this.getBioAssayDimensionFromCacheOrCreate(dataVector, c);
assert !this.isTransient(bioAssayDimension);
dataVector.setBioAssayDimension(bioAssayDimension);
assert dataVector.getQuantitationType() != null;
QuantitationType qt = this.persistQuantitationType(dataVector.getQuantitationType());
qt = (QuantitationType) this.getSessionFactory().getCurrentSession().merge(qt);
dataVector.setQuantitationType(qt);
return bioAssayDimension;
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class SampleCoexpressionMatrixServiceImpl method create.
@Override
public DoubleMatrix<BioAssay, BioAssay> create(ExpressionExperiment ee, boolean useRegression, boolean removeOutliers) {
// Load data and create matrix
ExpressionDataDoubleMatrix mat = this.loadDataMatrix(ee, useRegression, this.loadVectors(ee));
DoubleMatrix<BioAssay, BioAssay> cormat = this.loadCorMat(removeOutliers, mat);
// Check consistency
BioAssayDimension bestBioAssayDimension = mat.getBestBioAssayDimension();
if (cormat.rows() != bestBioAssayDimension.getBioAssays().size()) {
throw new IllegalStateException("Number of bioassays doesn't match length of the best bioAssayDimension. BAs in dimension: " + bestBioAssayDimension.getBioAssays().size() + ", rows in cormat: " + cormat.rows());
}
// Persist
sampleCoexpressionMatrixHelperService.create(cormat, bestBioAssayDimension, mat.getExpressionExperiment());
return cormat;
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class TwoChannelMissingValuesImpl method computeMissingValues.
@Override
public Collection<RawExpressionDataVector> computeMissingValues(ExpressionExperiment ee, double signalToNoiseThreshold, Collection<Double> extraMissingValueIndicators) {
ee = expressionExperimentService.thawLite(ee);
Collection<QuantitationType> usefulQuantitationTypes = ExpressionDataMatrixBuilder.getUsefulQuantitationTypes(ee);
StopWatch timer = new StopWatch();
timer.start();
TwoChannelMissingValuesImpl.log.info("Loading vectors ...");
Collection<RawExpressionDataVector> rawVectors = rawExpressionDataVectorService.find(usefulQuantitationTypes);
Collection<ProcessedExpressionDataVector> procVectors = new HashSet<>();
if (rawVectors.isEmpty()) {
procVectors = processedExpressionDataVectorService.find(usefulQuantitationTypes);
processedExpressionDataVectorService.thaw(procVectors);
} else {
rawExpressionDataVectorService.thaw(rawVectors);
}
timer.stop();
this.logTimeInfo(timer, procVectors.size() + rawVectors.size());
Collection<? extends DesignElementDataVector> builderVectors = new HashSet<>(rawVectors.isEmpty() ? procVectors : rawVectors);
System.out.println("Building matrix with vectors that I just thawed");
ExpressionDataMatrixBuilder builder = new ExpressionDataMatrixBuilder(builderVectors);
Collection<BioAssayDimension> dims = builder.getBioAssayDimensions();
/*
* Note we have to do this one array design at a time, because we are producing DesignElementDataVectors which
* must be associated with the correct BioAssayDimension.
*/
TwoChannelMissingValuesImpl.log.info("Study has " + dims.size() + " bioassaydimensions");
if (extraMissingValueIndicators != null && extraMissingValueIndicators.size() > 0) {
TwoChannelMissingValuesImpl.log.info("There are " + extraMissingValueIndicators.size() + " manually-set missing value indicators");
}
ExpressionDataDoubleMatrix preferredData = builder.getPreferredData();
ExpressionDataDoubleMatrix bkgDataA = builder.getBackgroundChannelA();
ExpressionDataDoubleMatrix bkgDataB = builder.getBackgroundChannelB();
ExpressionDataDoubleMatrix signalDataA = builder.getSignalChannelA();
ExpressionDataDoubleMatrix signalDataB = builder.getSignalChannelB();
if (builder.isAnyMissing()) {
if (bkgDataA != null) {
for (QuantitationType qt : bkgDataA.getQuantitationTypes()) {
if (builder.getNumMissingValues(qt) > 0) {
TwoChannelMissingValuesImpl.log.warn("Missing values in bkgDataA");
break;
}
}
}
if (bkgDataB != null) {
for (QuantitationType qt : bkgDataB.getQuantitationTypes()) {
if (builder.getNumMissingValues(qt) > 0) {
TwoChannelMissingValuesImpl.log.warn("Missing values in bkgDataB");
break;
}
}
}
if (signalDataA != null) {
for (QuantitationType qt : signalDataA.getQuantitationTypes()) {
if (builder.getNumMissingValues(qt) > 0) {
TwoChannelMissingValuesImpl.log.warn("Missing values in signalDataA");
break;
}
}
}
if (signalDataB != null) {
for (QuantitationType qt : signalDataB.getQuantitationTypes()) {
if (builder.getNumMissingValues(qt) > 0) {
TwoChannelMissingValuesImpl.log.warn("Missing values in signalDataB");
break;
}
}
}
}
Collection<RawExpressionDataVector> dimRes = this.computeMissingValues(ee, preferredData, signalDataA, signalDataB, bkgDataA, bkgDataB, signalToNoiseThreshold, extraMissingValueIndicators);
return new HashSet<>(dimRes);
}
use of ubic.gemma.model.expression.bioAssayData.BioAssayDimension in project Gemma by PavlidisLab.
the class SVDServiceHelperImpl method svdFactorAnalysis.
@Override
public SVDValueObject svdFactorAnalysis(PrincipalComponentAnalysis pca) {
BioAssayDimension bad = pca.getBioAssayDimension();
List<BioAssay> bioAssays = bad.getBioAssays();
SVDValueObject svo;
try {
svo = new SVDValueObject(pca);
} catch (Exception e) {
SVDServiceHelperImpl.log.error(e.getLocalizedMessage());
return null;
}
Map<Long, Date> bioMaterialDates = new HashMap<>();
Map<ExperimentalFactor, Map<Long, Double>> bioMaterialFactorMap = new HashMap<>();
this.prepareForFactorComparisons(svo, bioAssays, bioMaterialDates, bioMaterialFactorMap);
if (bioMaterialDates.isEmpty() && bioMaterialFactorMap.isEmpty()) {
SVDServiceHelperImpl.log.warn("No factor or date information to compare to the eigenGenes");
return svo;
}
Long[] svdBioMaterials = svo.getBioMaterialIds();
svo.getDateCorrelations().clear();
svo.getFactorCorrelations().clear();
svo.getDates().clear();
svo.getFactors().clear();
for (int componentNumber = 0; componentNumber < Math.min(svo.getvMatrix().columns(), SVDServiceHelperImpl.MAX_EIGEN_GENES_TO_TEST); componentNumber++) {
this.analyzeComponent(svo, componentNumber, svo.getvMatrix(), bioMaterialDates, bioMaterialFactorMap, svdBioMaterials);
}
return svo;
}
Aggregations