Search in sources :

Example 16 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class BaseExpressionDataMatrix method selectVectors.

Collection<DesignElementDataVector> selectVectors(Collection<? extends DesignElementDataVector> vectors, QuantitationType quantitationType) {
    this.quantitationTypes.add(quantitationType);
    Collection<DesignElementDataVector> vectorsOfInterest = new LinkedHashSet<>();
    int i = 0;
    for (DesignElementDataVector vector : vectors) {
        QuantitationType vectorQuantitationType = vector.getQuantitationType();
        if (vectorQuantitationType.equals(quantitationType)) {
            if (this.expressionExperiment == null)
                this.expressionExperiment = vector.getExpressionExperiment();
            vectorsOfInterest.add(vector);
            this.getQuantitationTypes().add(vectorQuantitationType);
            CompositeSequence designElement = vector.getDesignElement();
            bioAssayDimensions.put(designElement, vector.getBioAssayDimension());
            this.addToRowMaps(i, designElement);
            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 17 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ExpressionDataIntegerMatrix method createMatrix.

/**
 * Fill in the data
 *
 * @return DoubleMatrixNamed
 */
private IntegerMatrix<CompositeSequence, Integer> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
    int numRows = this.rowDesignElementMapByInteger.keySet().size();
    IntegerMatrix<CompositeSequence, Integer> mat = new IntegerMatrix<>(numRows, maxSize);
    for (int j = 0; j < mat.columns(); j++) {
        mat.addColumnName(j);
    }
    // initialize the matrix to 0
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            mat.set(i, j, 0);
        }
    }
    ByteArrayConverter bac = new ByteArrayConverter();
    Map<Integer, CompositeSequence> rowNames = new TreeMap<>();
    for (DesignElementDataVector vector : vectors) {
        CompositeSequence designElement = vector.getDesignElement();
        assert designElement != null : "No design element for " + vector;
        Integer rowIndex = this.rowElementMap.get(designElement);
        assert rowIndex != null;
        rowNames.put(rowIndex, designElement);
        byte[] bytes = vector.getData();
        int[] vals = bac.byteArrayToInts(bytes);
        BioAssayDimension dimension = vector.getBioAssayDimension();
        Collection<BioAssay> bioAssays = dimension.getBioAssays();
        assert bioAssays.size() == vals.length : "Expected " + vals.length + " got " + bioAssays.size();
        Iterator<BioAssay> it = bioAssays.iterator();
        this.setMatBioAssayValues(mat, rowIndex, ArrayUtils.toObject(vals), bioAssays, it);
    }
    for (int i = 0; i < mat.rows(); i++) {
        mat.addRowName(rowNames.get(i));
    }
    ExpressionDataIntegerMatrix.log.debug("Created a " + mat.rows() + " x " + mat.columns() + " matrix");
    return mat;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) IntegerMatrix(ubic.basecode.dataStructure.matrix.IntegerMatrix) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 18 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ExpressionDataStringMatrix method createMatrix.

private StringMatrix<Integer, Integer> createMatrix(Collection<? extends DesignElementDataVector> vectors, int maxSize) {
    int numRows = this.rowDesignElementMapByInteger.keySet().size();
    StringMatrix<Integer, Integer> mat = new StringMatrix<>(numRows, maxSize);
    for (int j = 0; j < mat.columns(); j++) {
        mat.addColumnName(j);
    }
    // initialize the matrix to "";
    for (int i = 0; i < mat.rows(); i++) {
        for (int j = 0; j < mat.columns(); j++) {
            mat.set(i, j, "");
        }
    }
    ByteArrayConverter bac = new ByteArrayConverter();
    for (DesignElementDataVector vector : vectors) {
        CompositeSequence designElement = vector.getDesignElement();
        assert designElement != null : "No designelement for " + vector;
        Integer rowIndex = this.rowElementMap.get(designElement);
        assert rowIndex != null;
        mat.addRowName(rowIndex);
        byte[] bytes = vector.getData();
        String[] vals = bac.byteArrayToStrings(bytes);
        BioAssayDimension dimension = vector.getBioAssayDimension();
        Collection<BioAssay> bioAssays = dimension.getBioAssays();
        assert bioAssays.size() == vals.length : "Expected " + vals.length + " got " + bioAssays.size();
        Iterator<BioAssay> it = bioAssays.iterator();
        for (int j = 0; j < bioAssays.size(); j++) {
            BioAssay bioAssay = it.next();
            Integer column = this.columnAssayMap.get(bioAssay);
            assert column != null;
            mat.setByKeys(rowIndex, column, vals[j]);
        }
    }
    ExpressionDataStringMatrix.log.debug("Created a " + mat.rows() + " x " + mat.columns() + " matrix");
    return mat;
}
Also used : ByteArrayConverter(ubic.basecode.io.ByteArrayConverter) StringMatrix(ubic.basecode.dataStructure.matrix.StringMatrix) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 19 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ProcessedExpressionDataVectorCreateHelperServiceImpl method loadIntensities.

/**
 * Computes expression intensities depending on which ArrayDesign TechnologyType is used.
 *
 * @return ExpressionDataDoubleMatrix
 */
private ExpressionDataDoubleMatrix loadIntensities(ExpressionExperiment ee, Collection<ProcessedExpressionDataVector> processedVectors) {
    Collection<ArrayDesign> arrayDesignsUsed = this.eeService.getArrayDesignsUsed(ee);
    assert !arrayDesignsUsed.isEmpty();
    ArrayDesign arrayDesign = arrayDesignsUsed.iterator().next();
    assert arrayDesign != null && arrayDesign.getTechnologyType() != null;
    ExpressionDataDoubleMatrix intensities;
    if (!arrayDesign.getTechnologyType().equals(TechnologyType.ONECOLOR) && !arrayDesign.getTechnologyType().equals(TechnologyType.NONE)) {
        ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities for two-color data from underlying data");
        /*
             * Get vectors needed to compute intensities.
             */
        Collection<QuantitationType> quantitationTypes = eeService.getQuantitationTypes(ee);
        Collection<QuantitationType> usefulQuantitationTypes = ExpressionDataMatrixBuilder.getUsefulQuantitationTypes(quantitationTypes);
        if (usefulQuantitationTypes.isEmpty()) {
            throw new IllegalStateException("No useful quantitation types for " + ee.getShortName());
        }
        Collection<? extends DesignElementDataVector> vectors = rawExpressionDataVectorService.find(usefulQuantitationTypes);
        if (vectors.isEmpty()) {
            vectors = processedExpressionDataVectorService.find(usefulQuantitationTypes);
        }
        if (vectors.isEmpty()) {
            throw new IllegalStateException("No vectors for useful quantitation types for " + ee.getShortName());
        }
        ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Vectors loaded ...");
        Collection<DesignElementDataVector> vs = new HashSet<>(vectors);
        rawExpressionDataVectorService.thawRawAndProcessed(vs);
        ExpressionDataMatrixBuilder builder = new ExpressionDataMatrixBuilder(processedVectors, vectors);
        intensities = builder.getIntensity();
        ExpressionDataBooleanMatrix missingValues = builder.getMissingValueData();
        if (missingValues == null) {
            ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate missing value matrix for " + ee + ", rank computation skipped (needed for two-color data)");
            return intensities;
        }
        if (intensities == null) {
            ProcessedExpressionDataVectorCreateHelperServiceImpl.log.warn("Could not locate intensity matrix for " + ee + ", rank computation skipped (needed for two-color data)");
            return null;
        }
        ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Masking ...");
        this.maskMissingValues(intensities, missingValues);
    } else {
        ProcessedExpressionDataVectorCreateHelperServiceImpl.log.info("Computing intensities directly from processed data");
        intensities = new ExpressionDataDoubleMatrix(processedVectors);
    }
    return intensities;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType)

Example 20 with DesignElementDataVector

use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.

the class ExpressionDataDoubleMatrixTest method testConstructExpressionDataDoubleMatrix.

/**
 * Tests the construction of an ExpressionDataDoubleMatrix
 */
@Test
public void testConstructExpressionDataDoubleMatrix() {
    /* test creating the ExpressionDataDoubleMatrix */
    QuantitationType quantitationType = QuantitationType.Factory.newInstance();
    quantitationType.setName(metaData.getQuantitationTypeName());
    quantitationType.setIsPreferred(true);
    quantitationType.setRepresentation(PrimitiveType.DOUBLE);
    quantitationType.setIsMaskedPreferred(false);
    quantitationType.setIsRatio(true);
    quantitationType.setIsBackground(false);
    quantitationType.setIsBackgroundSubtracted(true);
    quantitationType.setIsNormalized(true);
    Collection<RawExpressionDataVector> designElementDataVectors = ee.getRawExpressionDataVectors();
    Collection<CompositeSequence> designElements = new HashSet<>();
    for (DesignElementDataVector designElementDataVector : designElementDataVectors) {
        CompositeSequence de = designElementDataVector.getDesignElement();
        designElements.add(de);
    }
    /* Constructor 1 */
    ExpressionDataDoubleMatrix expressionDataDoubleMatrix = new ExpressionDataDoubleMatrix(designElementDataVectors);
    /* Assertions */
    CompositeSequence deToQuery = designElements.iterator().next();
    Double[] row = expressionDataDoubleMatrix.getRow(deToQuery);
    assertNotNull(row);
    for (Double aRow : row) {
        log.debug(aRow);
    }
    Double[][] dMatrix = expressionDataDoubleMatrix.getRawMatrix();
    assertEquals(dMatrix.length, 200);
    assertEquals(dMatrix[0].length, 59);
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) DesignElementDataVector(ubic.gemma.model.expression.bioAssayData.DesignElementDataVector) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) AbstractGeoServiceTest(ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest) Test(org.junit.Test)

Aggregations

DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)33 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)18 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)9 StandardQuantitationType (ubic.gemma.model.common.quantitationtype.StandardQuantitationType)9 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)8 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)5 ProcessedExpressionDataVector (ubic.gemma.model.expression.bioAssayData.ProcessedExpressionDataVector)5 Collection (java.util.Collection)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.Test)2 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)1