Search in sources :

Example 66 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class QuantitationTypeData method getQuantitationTypesNeeded.

/**
 * @return If there are multiple valid choices, we choose the first one seen, unless a later one has fewer missing value.
 */
private QuantitationTypeData getQuantitationTypesNeeded() {
    Collection<BioAssayDimension> dimensions = this.getBioAssayDimensions();
    QuantitationTypeData result = new QuantitationTypeData();
    this.populateMissingValueInfo();
    for (BioAssayDimension targetDimension : dimensions) {
        Collection<QuantitationType> checkedQts = new HashSet<>();
        for (DesignElementDataVector vector : vectors) {
            BioAssayDimension dim = vector.getBioAssayDimension();
            if (!dim.equals(targetDimension))
                continue;
            QuantitationType qType = vector.getQuantitationType();
            if (checkedQts.contains(qType))
                continue;
            checkedQts.add(qType);
            String name = qType.getName();
            if (qType.getIsPreferred() && result.getPreferred(dim) == null) {
                result.addPreferred(dim, qType);
                ExpressionDataMatrixBuilder.log.info("Preferred=" + qType);
            } else if (ChannelUtils.isBackgroundChannelA(name)) {
                if (result.getBackgroundChannelA(dim) != null) {
                    int i = numMissingValues.get(qType);
                    int j = numMissingValues.get(result.getBackgroundChannelA(dim));
                    if (i < j) {
                        ExpressionDataMatrixBuilder.log.info("Found better background A=" + qType);
                        result.addBackgroundChannelA(dim, qType);
                    }
                } else {
                    result.addBackgroundChannelA(dim, qType);
                    ExpressionDataMatrixBuilder.log.info("Background A=" + qType);
                }
            } else if (ChannelUtils.isBackgroundChannelB(name)) {
                if (result.getBackgroundChannelB(dim) != null) {
                    int i = numMissingValues.get(qType);
                    int j = numMissingValues.get(result.getBackgroundChannelB(dim));
                    if (i < j) {
                        ExpressionDataMatrixBuilder.log.info("Found better background B=" + qType);
                        result.addBackgroundChannelB(dim, qType);
                    }
                } else {
                    result.addBackgroundChannelB(dim, qType);
                    ExpressionDataMatrixBuilder.log.info("Background B=" + qType);
                }
            } else if (ChannelUtils.isSignalChannelA(name)) {
                if (result.getSignalChannelA(dim) != null) {
                    int i = numMissingValues.get(qType);
                    int j = numMissingValues.get(result.getSignalChannelA(dim));
                    if (i < j) {
                        ExpressionDataMatrixBuilder.log.info("Found better Signal A=" + qType);
                        result.addSignalChannelA(dim, qType);
                    }
                } else {
                    result.addSignalChannelA(dim, qType);
                    ExpressionDataMatrixBuilder.log.info("Signal A=" + qType);
                }
            } else if (ChannelUtils.isSignalChannelB(name)) {
                if (result.getSignalChannelB(dim) != null) {
                    int i = numMissingValues.get(qType);
                    int j = numMissingValues.get(result.getSignalChannelB(dim));
                    if (i < j) {
                        ExpressionDataMatrixBuilder.log.info("Found better Signal B=" + qType);
                        result.addSignalChannelB(dim, qType);
                    }
                } else {
                    result.addSignalChannelB(dim, qType);
                    ExpressionDataMatrixBuilder.log.info("Signal B=" + qType);
                }
            } else if (name.matches("CH1D_MEAN")) {
                // specific for SGD data bug
                result.addBkgSubChannelA(dim, qType);
            }
            if (!anyMissing && result.getSignalChannelA(dim) != null && result.getSignalChannelB(dim) != null && result.getBackgroundChannelA(dim) != null && result.getBackgroundChannelB(dim) != null && result.getPreferred(dim) != null) {
                // no need to go through them all.
                break;
            }
        }
    }
    return result;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType)

Example 67 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class BaseExpressionDataMatrix method selectVectors.

Collection<DesignElementDataVector> selectVectors(Collection<? extends DesignElementDataVector> vectors, List<QuantitationType> qTypes) {
    this.quantitationTypes.addAll(qTypes);
    List<DesignElementDataVector> sorted = this.sortVectorsByDesignElement(vectors);
    Collection<DesignElementDataVector> vectorsOfInterest = new LinkedHashSet<>();
    int rowIndex = 0;
    for (QuantitationType soughtType : qTypes) {
        for (DesignElementDataVector vector : sorted) {
            QuantitationType vectorQuantitationType = vector.getQuantitationType();
            if (vectorQuantitationType.equals(soughtType)) {
                if (this.expressionExperiment == null)
                    this.expressionExperiment = vector.getExpressionExperiment();
                vectorsOfInterest.add(vector);
                this.getQuantitationTypes().add(vectorQuantitationType);
                CompositeSequence designElement = vector.getDesignElement();
                this.bioAssayDimensions.put(designElement, vector.getBioAssayDimension());
                this.addToRowMaps(rowIndex, designElement);
                rowIndex++;
            }
        }
    }
    BaseExpressionDataMatrix.log.debug("Selected " + vectorsOfInterest.size() + " vectors");
    return vectorsOfInterest;
}
Also used : DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 68 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class BaseExpressionDataMatrix method selectVectors.

Collection<DesignElementDataVector> selectVectors(Collection<? extends DesignElementDataVector> vectors, Collection<QuantitationType> qTypes) {
    this.quantitationTypes.addAll(qTypes);
    Collection<DesignElementDataVector> vectorsOfInterest = new LinkedHashSet<>();
    int i = 0;
    for (DesignElementDataVector vector : vectors) {
        QuantitationType vectorQuantitationType = vector.getQuantitationType();
        if (qTypes.contains(vectorQuantitationType)) {
            if (this.expressionExperiment == null)
                this.expressionExperiment = vector.getExpressionExperiment();
            vectorsOfInterest.add(vector);
            CompositeSequence designElement = vector.getDesignElement();
            bioAssayDimensions.put(designElement, vector.getBioAssayDimension());
            this.addToRowMaps(i, designElement);
            this.getQuantitationTypes().add(vectorQuantitationType);
            i++;
        }
    }
    return vectorsOfInterest;
}
Also used : DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Example 69 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class ExpressionDataDoubleMatrix method toProcessedDataVectors.

/**
 * @return Convert this to a collection of vectors.
 */
public Collection<ProcessedExpressionDataVector> toProcessedDataVectors() {
    Collection<ProcessedExpressionDataVector> result = new HashSet<>();
    QuantitationType qt = this.getQuantitationTypes().iterator().next();
    ByteArrayConverter bac = new ByteArrayConverter();
    if (this.getQuantitationTypes().size() > 1) {
        throw new UnsupportedOperationException("Cannot convert matrix that has more than one quantitation type");
    }
    for (int i = 0; i < this.rows(); i++) {
        Double[] data = this.getRow(i);
        ProcessedExpressionDataVector v = ProcessedExpressionDataVector.Factory.newInstance();
        v.setBioAssayDimension(this.getBestBioAssayDimension());
        v.setDesignElement(this.getRowNames().get(i));
        v.setQuantitationType(qt);
        v.setData(bac.doubleArrayToBytes(data));
        v.setExpressionExperiment(this.expressionExperiment);
        // we don't fill in the ranks because we only have the mean value here.
        result.add(v);
    }
    return result;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) ProcessedExpressionDataVector(ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Example 70 with QuantitationType

use of ubic.gemma.model.common.quantitationtype.QuantitationType in project Gemma by PavlidisLab.

the class RNASeqDataAddCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception exception = super.processCommandLine(args);
    if (exception != null)
        return exception;
    DataUpdater serv = this.getBean(DataUpdater.class);
    if (this.justbackfillLog2cpm) {
        for (BioAssaySet bas : this.expressionExperiments) {
            try {
                ExpressionExperiment ee = (ExpressionExperiment) bas;
                Collection<QuantitationType> pqts = this.eeService.getPreferredQuantitationType(ee);
                if (pqts.size() > 1)
                    throw new IllegalArgumentException("Cannot process when there is more than one preferred QT");
                if (pqts.isEmpty())
                    throw new IllegalArgumentException("No preferred quantitation type for " + ee.getShortName());
                QuantitationType qt = pqts.iterator().next();
                if (!qt.getType().equals(StandardQuantitationType.COUNT)) {
                    AbstractCLI.log.warn("Preferred data is not counts for " + ee);
                    this.errorObjects.add(ee.getShortName() + ": Preferred data is not counts");
                    continue;
                }
                serv.log2cpmFromCounts(ee, qt);
                this.successObjects.add(ee);
            } catch (Exception e) {
                AbstractCLI.log.error(e, e);
                this.errorObjects.add(((ExpressionExperiment) bas).getShortName() + ": " + e.getMessage());
            }
        }
        this.summarizeProcessing();
        return null;
    }
    /*
         * Usual cases.
         */
    if (this.expressionExperiments.size() > 1) {
        throw new IllegalArgumentException("Sorry, can only process one experiment with this tool.");
    }
    ArrayDesign targetArrayDesign = this.locateArrayDesign(this.platformName);
    ExpressionExperiment ee = (ExpressionExperiment) this.expressionExperiments.iterator().next();
    if (this.expressionExperiments.size() > 1) {
        AbstractCLI.log.warn("This CLI can only deal with one experiment at a time; only the first one will be processed");
    }
    DoubleMatrixReader reader = new DoubleMatrixReader();
    try {
        DoubleMatrix<String, String> countMatrix = null;
        DoubleMatrix<String, String> rpkmMatrix = null;
        if (this.countFile != null) {
            countMatrix = reader.read(countFile);
        }
        if (this.rpkmFile != null) {
            rpkmMatrix = reader.read(rpkmFile);
        }
        serv.addCountData(ee, targetArrayDesign, countMatrix, rpkmMatrix, readLength, isPairedReads, allowMissingSamples);
    } catch (IOException e) {
        AbstractCLI.log.error("Failed while processing " + ee, e);
        return e;
    }
    return null;
}
Also used : BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) DataUpdater(ubic.gemma.core.loader.expression.geo.DataUpdater) IOException(java.io.IOException) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) StandardQuantitationType(ubic.gemma.model.common.quantitationtype.StandardQuantitationType) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) IOException(java.io.IOException) DoubleMatrixReader(ubic.basecode.io.reader.DoubleMatrixReader)

Aggregations

QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)74 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)30 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)20 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)18 Test (org.junit.Test)16 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)14 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)13 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)11 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)10 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)10 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)8 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)7 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)6 GeoDomainObjectGeneratorLocal (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGeneratorLocal)6 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)6 InputStream (java.io.InputStream)5 GZIPInputStream (java.util.zip.GZIPInputStream)5 GeoSeries (ubic.gemma.core.loader.expression.geo.model.GeoSeries)5 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)5 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)4