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);
}
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());
}
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++;
}
}
}
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);
}
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;
}
Aggregations