Search in sources :

Example 36 with BioAssayDimension

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;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 37 with BioAssayDimension

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;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Example 38 with 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;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 39 with BioAssayDimension

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);
}
Also used : ExpressionDataDoubleMatrix(ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) StopWatch(org.apache.commons.lang3.time.StopWatch) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) HashSet(java.util.HashSet)

Example 40 with BioAssayDimension

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;
}
Also used : ExperimentalFactor(ubic.gemma.model.expression.experiment.ExperimentalFactor) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)59 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)29 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)20 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)15 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)15 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)15 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)11 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)10 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)9 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)9 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)6 HashSet (java.util.HashSet)4 Test (org.junit.Test)4 Transactional (org.springframework.transaction.annotation.Transactional)4 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)4 StopWatch (org.apache.commons.lang3.time.StopWatch)3 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)3 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)3 DoubleArrayList (cern.colt.list.DoubleArrayList)2