Search in sources :

Example 61 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionDataDoubleMatrix method toString.

@Override
public String toString() {
    int columns = this.columns();
    int rows = this.rows();
    NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(4);
    StringBuilder buf = new StringBuilder();
    if (rows <= ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING) {
        buf.append(rows).append(" x ").append(columns).append(" matrix of double values\n");
    } else {
        buf.append(rows).append(" x ").append(columns).append(" matrix of double values, showing up to ").append(ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING).append(" rows\n");
    }
    int stop = 0;
    buf.append("Probe");
    for (int i = 0; i < columns; i++) {
        buf.append("\t").append(this.getBioMaterialForColumn(i).getName()).append(":");
        for (BioAssay ba : this.getBioAssaysForColumn(i)) {
            buf.append(ba.getName()).append(",");
        }
    }
    buf.append("\n");
    for (int j = 0; j < rows; j++) {
        buf.append(this.rowDesignElementMapByInteger.get(j).getName());
        for (int i = 0; i < columns; i++) {
            Double val = this.get(j, i);
            if (Double.isNaN(val)) {
                buf.append("\t").append(val);
            } else {
                buf.append("\t").append(nf.format(this.get(j, i)));
            }
        }
        buf.append("\n");
        if (stop++ > ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING) {
            buf.append("\n(Stopping after " + ExpressionDataDoubleMatrix.MAX_ROWS_TO_STRING + " rows) ...\n");
            break;
        }
    }
    return buf.toString();
}
Also used : BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) NumberFormat(java.text.NumberFormat)

Example 62 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay 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 63 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class ExpressionDataMatrixColumnSort method orderByExperimentalDesign.

public static <R> DoubleMatrix<R, BioAssay> orderByExperimentalDesign(DoubleMatrix<R, BioAssay> mat) {
    List<BioAssay> bioAssays = mat.getColNames();
    List<BioMaterial> start = new ArrayList<>();
    Map<BioMaterial, BioAssay> bm2ba = new HashMap<>();
    for (BioAssay bioAssay : bioAssays) {
        start.add(bioAssay.getSampleUsed());
        bm2ba.put(bioAssay.getSampleUsed(), bioAssay);
    }
    List<BioMaterial> bm = ExpressionDataMatrixColumnSort.orderByExperimentalDesign(start, null);
    List<BioAssay> newBioAssayOrder = new ArrayList<>();
    for (BioMaterial bioMaterial : bm) {
        assert bm2ba.containsKey(bioMaterial);
        newBioAssayOrder.add(bm2ba.get(bioMaterial));
    }
    return mat.subsetColumns(newBioAssayOrder);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 64 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay 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 65 with BioAssay

use of ubic.gemma.model.expression.bioAssay.BioAssay in project Gemma by PavlidisLab.

the class DataUpdater method addData.

/**
 * Add an additional data (with associated quantitation type) to the selected experiment. Will do postprocessing if
 * the data quantitationType is 'preferred', but if there is already a preferred quantitation type, an error will be
 * thrown.
 *
 * @param ee             ee
 * @param targetPlatform optional; if null, uses the platform already used (if there is just one; you can't use this
 *                       for a multi-platform dataset)
 * @param data           to slot in
 * @return ee
 */
public ExpressionExperiment addData(ExpressionExperiment ee, ArrayDesign targetPlatform, ExpressionDataDoubleMatrix data) {
    if (data.rows() == 0) {
        throw new IllegalArgumentException("Data had no rows");
    }
    Collection<QuantitationType> qts = data.getQuantitationTypes();
    if (qts.size() > 1) {
        throw new IllegalArgumentException("Only support a single quantitation type");
    }
    if (qts.isEmpty()) {
        throw new IllegalArgumentException("Please supply a quantitation type with the data");
    }
    QuantitationType qt = qts.iterator().next();
    if (qt.getIsPreferred()) {
        for (QuantitationType existingQt : ee.getQuantitationTypes()) {
            if (existingQt.getIsPreferred()) {
                throw new IllegalArgumentException("You cannot add 'preferred' data to an experiment that already has it. You should first make the existing data non-preferred.");
            }
        }
    }
    Collection<RawExpressionDataVector> vectors = this.makeNewVectors(ee, targetPlatform, data, qt);
    if (vectors.isEmpty()) {
        throw new IllegalStateException("no vectors!");
    }
    ee = experimentService.addRawVectors(ee, vectors);
    this.audit(ee, "Data vectors added for " + targetPlatform + ", " + qt, false);
    // debug code.
    for (BioAssay ba : ee.getBioAssays()) {
        assert ba.getArrayDesignUsed().equals(targetPlatform);
    }
    experimentService.update(ee);
    if (qt.getIsPreferred()) {
        DataUpdater.log.info("Postprocessing preferred data");
        ee = this.postprocess(ee);
        assert ee.getNumberOfDataVectors() != null;
    }
    return ee;
}
Also used : RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)144 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)67 Test (org.junit.Test)29 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)29 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)24 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)20 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)18 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)15 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)14 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)14 InputStream (java.io.InputStream)11 ByteArrayConverter (ubic.basecode.io.ByteArrayConverter)10 HashSet (java.util.HashSet)9 AlreadyExistsInSystemException (ubic.gemma.core.loader.util.AlreadyExistsInSystemException)8 DesignElementDataVector (ubic.gemma.model.expression.bioAssayData.DesignElementDataVector)8 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)7