Search in sources :

Example 1 with SampleCoexpressionMatrix

use of ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix in project Gemma by PavlidisLab.

the class SampleCoexpressionAnalysisDaoImpl method load.

@Override
public DoubleMatrix<BioAssay, BioAssay> load(ExpressionExperiment ee) {
    Collection<SampleCoexpressionMatrix> r = this.findByExperiment(ee);
    if (r.isEmpty())
        return null;
    if (r.size() > 1) {
        AbstractDao.log.warn("More than one matrix was available, only the first is being returned.");
    }
    SampleCoexpressionMatrix matObj = r.iterator().next();
    byte[] matrixBytes = matObj.getCoexpressionMatrix();
    final List<BioAssay> bioAssays = matObj.getBioAssayDimension().getBioAssays();
    int numBa = bioAssays.size();
    if (numBa == 0) {
        throw new IllegalArgumentException("No bioassays in the bioassaydimension with id=" + matObj.getBioAssayDimension().getId());
    }
    double[][] rawMatrix;
    try {
        rawMatrix = SampleCoexpressionAnalysisDaoImpl.bac.byteArrayToDoubleMatrix(matrixBytes, numBa);
    } catch (IllegalArgumentException e) {
        AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getMessage());
        return null;
    }
    DoubleMatrix<BioAssay, BioAssay> result = new DenseDoubleMatrix<>(rawMatrix);
    try {
        result.setRowNames(bioAssays);
    } catch (IllegalArgumentException e) {
        AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getLocalizedMessage());
    }
    try {
        result.setColumnNames(bioAssays);
    } catch (IllegalArgumentException e) {
        AbstractDao.log.error("EE id = " + ee.getId() + ": " + e.getLocalizedMessage());
    }
    return result;
}
Also used : SampleCoexpressionMatrix(ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 2 with SampleCoexpressionMatrix

use of ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix in project Gemma by PavlidisLab.

the class SampleCoexpressionAnalysisDaoImpl method create.

@Override
public SampleCoexpressionAnalysis create(DoubleMatrix<BioAssay, BioAssay> matrix, BioAssayDimension bad, ExpressionExperiment ee) {
    /*
         * First remove any old ones for the experiment.
         */
    Collection<SampleCoexpressionAnalysis> old = this.findAnalysesByExperiment(ee);
    this.remove(old);
    SampleCoexpressionAnalysis sas = SampleCoexpressionAnalysis.Factory.newInstance();
    sas.setExperimentAnalyzed(ee);
    SampleCoexpressionMatrix scm = SampleCoexpressionMatrix.Factory.newInstance();
    scm.setBioAssayDimension(bad);
    byte[] coexpressionMatrix = SampleCoexpressionAnalysisDaoImpl.bac.doubleMatrixToBytes(matrix.getRawMatrix());
    scm.setCoexpressionMatrix(coexpressionMatrix);
    sas.setSampleCoexpressionMatrix(scm);
    this.getSessionFactory().getCurrentSession().save(sas);
    return sas;
}
Also used : SampleCoexpressionMatrix(ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix) SampleCoexpressionAnalysis(ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionAnalysis)

Aggregations

SampleCoexpressionMatrix (ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionMatrix)2 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)1 SampleCoexpressionAnalysis (ubic.gemma.model.analysis.expression.coexpression.SampleCoexpressionAnalysis)1 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)1