Search in sources :

Example 66 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class AnnotationController method removeBiomaterialTag.

public void removeBiomaterialTag(Characteristic vc, Long id) {
    BioMaterial bm = bioMaterialService.load(id);
    if (bm == null) {
        throw new IllegalArgumentException("No such BioMaterial with id=" + id);
    }
    bioMaterialService.thaw(bm);
    ontologyService.removeBioMaterialStatement(vc.getId(), bm);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial)

Example 67 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class ExperimentalDesignControllerImpl method updateBioMaterials.

@Override
public void updateBioMaterials(BioMaterialValueObject[] bmvos) {
    if (bmvos == null || bmvos.length == 0)
        return;
    Collection<BioMaterial> biomaterials = bioMaterialService.updateBioMaterials(Arrays.asList(bmvos));
    if (biomaterials.isEmpty())
        return;
    BioMaterial bm = biomaterials.iterator().next();
    ExpressionExperiment ee = expressionExperimentService.findByBioMaterial(bm);
    if (ee == null)
        throw new IllegalStateException("No Experiment for biomaterial: " + bm);
    ee = expressionExperimentService.thawLite(ee);
    for (ExperimentalFactor ef : ee.getExperimentalDesign().getExperimentalFactors()) {
        if (ef.getType().equals(FactorType.CONTINUOUS)) {
            /*
                 * Check for unused factorValues
                 */
            Collection<FactorValue> usedFactorValues = new HashSet<>();
            LinearModelAnalyzer.populateFactorValuesFromBASet(ee, ef, usedFactorValues);
            Collection<FactorValue> toDelete = new HashSet<>();
            for (FactorValue fv : ef.getFactorValues()) {
                if (!usedFactorValues.contains(fv)) {
                    /*
                         * remove it.
                         */
                    toDelete.add(fv);
                }
            }
            if (!toDelete.isEmpty()) {
                log.info("Deleting " + toDelete.size() + " unused factorvalues for " + ef);
                factorValueDeletion.deleteFactorValues(EntityUtils.getIds(toDelete));
            }
        }
    }
    StringBuilder details = new StringBuilder("Updated bio materials:\n");
    for (BioMaterialValueObject vo : bmvos) {
        if (vo == null) {
            continue;
        }
        BioMaterial ba = bioMaterialService.load(vo.getId());
        if (ba != null) {
            details.append("id: ").append(ba.getId()).append(" - ").append(ba.getName()).append("\n");
        }
    }
    this.auditTrailService.addUpdateEvent(ee, ExperimentalDesignUpdatedEvent.class, "BioMaterials updated (" + bmvos.length + " items)", details.toString());
    this.experimentReportService.evictFromCache(ee.getId());
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioMaterialValueObject(ubic.gemma.model.expression.biomaterial.BioMaterialValueObject)

Example 68 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class ExpressionExperimentController method unmatchAllBioAssays.

/**
 * Completely reset the pairing of bioassays to biomaterials so they are no longer paired. New biomaterials are
 * constructed where necessary; they retain the characteristics of the original. Experimental design might need to
 * be redone after this operation. (AJAX)
 *
 * @param eeId ee id
 */
public void unmatchAllBioAssays(Long eeId) {
    ExpressionExperiment ee = this.expressionExperimentService.load(eeId);
    if (ee == null) {
        throw new IllegalArgumentException("Could not load experiment with id=" + eeId);
    }
    ee = expressionExperimentService.thawLite(ee);
    Collection<BioMaterial> needToProcess = new HashSet<>();
    for (BioAssay ba : ee.getBioAssays()) {
        BioMaterial bm = ba.getSampleUsed();
        this.bioMaterialService.thaw(bm);
        Collection<BioAssay> bioAssaysUsedIn = bm.getBioAssaysUsedIn();
        if (bioAssaysUsedIn.size() > 1) {
            needToProcess.add(bm);
        }
    }
    // FIXME this should be in a transaction!
    for (BioMaterial bm : needToProcess) {
        int i = 0;
        for (BioAssay baU : bm.getBioAssaysUsedIn()) {
            if (i > 0) {
                BioMaterial newMaterial = bioMaterialService.copy(bm);
                this.bioMaterialService.thaw(newMaterial);
                newMaterial.setName("Modeled after " + bm.getName());
                newMaterial.getFactorValues().clear();
                newMaterial.getBioAssaysUsedIn().add(baU);
                newMaterial = (BioMaterial) persisterHelper.persist(newMaterial);
                baU.setSampleUsed(newMaterial);
                bioAssayService.update(baU);
            }
            i++;
        }
    }
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 69 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class SampleCoexpressionMatrixServiceImpl method getMatrix.

private static DoubleMatrix<BioAssay, BioAssay> getMatrix(ExpressionDataDoubleMatrix matrix) {
    DoubleMatrix<BioMaterial, CompositeSequence> transposeR = matrix.getMatrix().transpose();
    DoubleMatrix<BioAssay, CompositeSequence> transpose = new DenseDoubleMatrix<>(transposeR.getRawMatrix());
    transpose.setColumnNames(transposeR.getColNames());
    for (int i = 0; i < transpose.rows(); i++) {
        BioAssay s = transposeR.getRowName(i).getBioAssaysUsedIn().iterator().next();
        transpose.setRowName(s, i);
    }
    return MatrixStats.correlationMatrix(transpose);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) DenseDoubleMatrix(ubic.basecode.dataStructure.matrix.DenseDoubleMatrix) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 70 with BioMaterial

use of ubic.gemma.model.expression.biomaterial.BioMaterial in project Gemma by PavlidisLab.

the class BatchInfoParser method getBatchInformationFromFiles.

/**
 * Now we can parse the file to get the batch information.
 * We allow ourselves to add dates to _some_ of the bioassays. It turns out to be common for there to be a single
 * corrupted date in CEL files, for example. However, downstream code has to be careful, and the batch factor could
 * be a problem too.
 *
 * @param bioAssays2Files BA 2 files
 * @return map of biomaterials to dates. Biomaterials which did not have associated dates are not included in the
 * map.
 */
private Map<BioMaterial, Date> getBatchInformationFromFiles(Map<BioAssay, File> bioAssays2Files) {
    Map<BioMaterial, Date> result = new HashMap<>();
    Collection<File> missingDate = new HashSet<>();
    for (BioAssay ba : bioAssays2Files.keySet()) {
        File f = bioAssays2Files.get(ba);
        ArrayDesign arrayDesignUsed = ba.getArrayDesignUsed();
        try (InputStream is = FileTools.getInputStreamFromPlainOrCompressedFile(f.getAbsolutePath())) {
            this.locateExtractor(arrayDesignUsed, ba, f);
            Date d = scanDateExtractor.extract(is);
            // to be okay, but let's assume we're not getting data the same day it was generated!
            if (d != null && d.after(new Date())) {
                throw new RuntimeException("Date was in the future for: " + ba + " from " + f.getName());
            }
            BioMaterial bm = ba.getSampleUsed();
            result.put(bm, d);
        } catch (RuntimeException | IOException e) {
            BatchInfoParser.log.warn("Failure while parsing: " + f + ": " + e.getMessage());
            missingDate.add(f);
        }
    }
    if (missingDate.size() == bioAssays2Files.size()) {
        throw new IllegalStateException("Dates were not found for any of the files.");
    }
    if (missingDate.size() > 0) {
        BatchInfoParser.log.warn("Dates were not obtained for " + missingDate + " files: ");
        for (File f : missingDate) {
            BatchInfoParser.log.info("Missing date for: " + f.getName());
        }
    }
    return result;
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) InputStream(java.io.InputStream) IOException(java.io.IOException) File(java.io.File) LocalFile(ubic.gemma.model.common.description.LocalFile) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Aggregations

BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)132 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)67 FactorValue (ubic.gemma.model.expression.experiment.FactorValue)27 ExperimentalFactor (ubic.gemma.model.expression.experiment.ExperimentalFactor)22 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)19 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)15 HashSet (java.util.HashSet)13 Test (org.junit.Test)13 ExpressionDataDoubleMatrix (ubic.gemma.core.datastructure.matrix.ExpressionDataDoubleMatrix)12 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)12 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)10 InputStream (java.io.InputStream)7 DenseDoubleMatrix (ubic.basecode.dataStructure.matrix.DenseDoubleMatrix)7 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)7 QuantitationType (ubic.gemma.model.common.quantitationtype.QuantitationType)7 Characteristic (ubic.gemma.model.common.description.Characteristic)6 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)6 DoubleArrayList (cern.colt.list.DoubleArrayList)5 DoubleMatrix1D (cern.colt.matrix.DoubleMatrix1D)5 ArrayList (java.util.ArrayList)5