use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class DesignElementDataVectorDaoImpl method thawRawAndProcessed.
@Override
public void thawRawAndProcessed(Collection<DesignElementDataVector> designElementDataVectors) {
if (designElementDataVectors == null)
return;
Session session = this.getSessionFactory().getCurrentSession();
Hibernate.initialize(designElementDataVectors);
StopWatch timer = new StopWatch();
timer.start();
Collection<ExpressionExperiment> ees = new HashSet<>();
Map<BioAssayDimension, Collection<DesignElementDataVector>> dims = new HashMap<>();
Collection<CompositeSequence> cs = new HashSet<>();
for (DesignElementDataVector vector : designElementDataVectors) {
session.buildLockRequest(LockOptions.NONE).lock(vector);
Hibernate.initialize(vector);
Hibernate.initialize(vector.getQuantitationType());
BioAssayDimension bad = vector.getBioAssayDimension();
if (!dims.containsKey(bad)) {
dims.put(bad, new HashSet<DesignElementDataVector>());
}
dims.get(bad).add(vector);
cs.add(vector.getDesignElement());
ees.add(vector.getExpressionExperiment());
session.evict(vector.getQuantitationType());
session.evict(vector);
}
if (timer.getTime() > designElementDataVectors.size()) {
AbstractDao.log.info("Thaw phase 1, " + designElementDataVectors.size() + " vectors initialized in " + timer.getTime() + "ms ");
}
timer.reset();
timer.start();
// lightly thawRawAndProcessed the EEs we saw
for (ExpressionExperiment ee : ees) {
Hibernate.initialize(ee);
session.evict(ee);
}
if (timer.getTime() > 200) {
AbstractDao.log.info("Thaw phase 2, " + ees.size() + " vector-associated expression experiments in " + timer.getTime() + "ms ");
}
timer.reset();
timer.start();
// thawRawAndProcessed the bioassayDimensions we saw -- usually one, more rarely two.
for (BioAssayDimension bad : dims.keySet()) {
BioAssayDimension tbad = (BioAssayDimension) this.getSessionFactory().getCurrentSession().createQuery("select distinct bad from BioAssayDimension bad join fetch bad.bioAssays ba join fetch ba.sampleUsed " + "bm join fetch ba.arrayDesignUsed left join fetch bm.factorValues fetch all properties where bad.id= :bad ").setParameter("bad", bad.getId()).uniqueResult();
assert tbad != null;
assert !dims.get(tbad).isEmpty();
for (DesignElementDataVector v : designElementDataVectors) {
if (v.getBioAssayDimension().getId().equals(tbad.getId())) {
v.setBioAssayDimension(tbad);
}
}
}
if (timer.getTime() > 1000) {
AbstractDao.log.info("Thaw phase 3, " + dims.size() + " vector-associated bioassaydimensions in " + timer.getTime() + "ms ");
}
timer.reset();
timer.start();
// thawRawAndProcessed the designelements we saw. SLOW
long lastTime = 0;
int count = 0;
for (CompositeSequence de : cs) {
BioSequence seq = de.getBiologicalCharacteristic();
if (seq == null)
continue;
session.buildLockRequest(LockOptions.NONE).lock(seq);
Hibernate.initialize(seq);
// is this really necessary?
ArrayDesign arrayDesign = de.getArrayDesign();
Hibernate.initialize(arrayDesign);
if (++count % 10000 == 0) {
if (timer.getTime() - lastTime > 1000) {
AbstractDao.log.info("Thawed " + count + " vector-associated probes " + timer.getTime() + " ms");
}
lastTime = timer.getTime();
}
}
timer.stop();
if (designElementDataVectors.size() >= 2000 || timer.getTime() > 200) {
AbstractDao.log.info("Thaw phase 4 " + cs.size() + " vector-associated probes thawed in " + timer.getTime() + "ms");
}
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class GeoConverterTest method checkQts.
private boolean checkQts(ExpressionExperiment ee) {
boolean ok = false;
for (DesignElementDataVector dedv : ee.getRawExpressionDataVectors()) {
QuantitationType qt = dedv.getQuantitationType();
if (qt.getIsPreferred()) {
ok = true;
assertEquals("VALUE", qt.getName());
}
}
return ok;
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class MatrixConversionTest method getDesignElementDataVectors.
/**
* Creates an ugly (but not unusual) situation where there are two bioassay dimensions with different sizes,
* referring to the same set of biomaterials.
*
* @return design element data vectors
*/
private Collection<DesignElementDataVector> getDesignElementDataVectors(Collection<QuantitationType> quantTypes) {
Collection<DesignElementDataVector> vectors = new HashSet<>();
ArrayDesign ad = ArrayDesign.Factory.newInstance();
ad.setName("junk");
List<CompositeSequence> sequences = this.getCompositeSequences(ad);
ArrayDesign adb = ArrayDesign.Factory.newInstance();
adb.setName("bjunk");
List<CompositeSequence> sequencesb = this.getCompositeSequences(ad);
// resused
List<BioMaterial> bioMaterials = this.getBioMaterials();
for (QuantitationType quantType : quantTypes) {
/*
* Create two bioassay dimension which overlap; "A" does not use all the biomaterials.
*/
BioAssayDimension baDimA = BioAssayDimension.Factory.newInstance();
Iterator<BioMaterial> bmita = bioMaterials.iterator();
for (long i = 0; i < MatrixConversionTest.NUM_BIOMATERIALS - 20; i++) {
BioAssay ba = ubic.gemma.model.expression.bioAssay.BioAssay.Factory.newInstance();
ba.setName(RandomStringUtils.randomNumeric(5) + "_testbioassay");
ba.setSampleUsed(bmita.next());
ba.setArrayDesignUsed(ad);
ba.setId(i);
baDimA.getBioAssays().add(ba);
}
baDimA.setName(RandomStringUtils.randomAlphanumeric(10));
BioAssayDimension baDimB = BioAssayDimension.Factory.newInstance();
Iterator<BioMaterial> bmitb = bioMaterials.iterator();
for (long i = 0; i < MatrixConversionTest.NUM_BIOMATERIALS; i++) {
BioAssay ba = ubic.gemma.model.expression.bioAssay.BioAssay.Factory.newInstance();
ba.setName(RandomStringUtils.randomNumeric(15) + "_testbioassay");
ba.setSampleUsed(bmitb.next());
ba.setArrayDesignUsed(adb);
ba.setId(i + 20);
baDimB.getBioAssays().add(ba);
}
baDimB.setName(RandomStringUtils.randomAlphanumeric(10));
// bio.a gets cs 0-99, bio.b gets 100-199.
long j = 0;
j = this.loopVectors(vectors, sequencesb, quantType, baDimA, j, MatrixConversionTest.NUM_CS - 100);
// noinspection UnusedAssignment // Better readability
j = this.loopVectors(vectors, sequences, quantType, baDimB, j, MatrixConversionTest.NUM_CS);
}
return vectors;
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class MatrixConversionTest method loopVectors.
private long loopVectors(Collection<DesignElementDataVector> vectors, List<CompositeSequence> sequencesb, QuantitationType quantType, BioAssayDimension baDimA, long j, int i2) {
for (; j < i2; j++) {
DesignElementDataVector vector = RawExpressionDataVector.Factory.newInstance();
double[] data = new double[baDimA.getBioAssays().size()];
for (int k = 0; k < data.length; k++) {
data[k] = k;
}
ByteArrayConverter bconverter = new ByteArrayConverter();
byte[] bdata = bconverter.doubleArrayToBytes(data);
vector.setData(bdata);
CompositeSequence cs = sequencesb.get((int) j);
vector.setDesignElement(cs);
vector.setQuantitationType(quantType);
vector.setBioAssayDimension(baDimA);
vectors.add(vector);
}
return j;
}
use of ubic.gemma.model.expression.bioAssayData.DesignElementDataVector in project Gemma by PavlidisLab.
the class ExpressionExperimentPrePersistServiceImpl method prepare.
@Override
public ArrayDesignsForExperimentCache prepare(ExpressionExperiment ee, ArrayDesignsForExperimentCache cache) {
Map<ArrayDesign, Collection<CompositeSequence>> newprobes = new HashMap<>();
Collection<DesignElementDataVector> dataVectorsThatNeedNewProbes = new HashSet<>();
/*
* First time through.
*/
Collection<RawExpressionDataVector> vectors = ee.getRawExpressionDataVectors();
if (vectors.isEmpty()) {
/*
* That's okay; some data sets don't come with data.
*/
this.prepareWithoutData(ee, cache);
}
for (DesignElementDataVector dataVector : vectors) {
CompositeSequence probe = dataVector.getDesignElement();
assert probe != null;
ArrayDesign arrayDesign = probe.getArrayDesign();
assert arrayDesign != null : probe + " does not have an array design";
arrayDesign = this.loadOrPersistArrayDesignAndAddToCache(arrayDesign, cache);
CompositeSequence cachedProbe = cache.getFromCache(probe);
if (cachedProbe == null) {
if (!newprobes.containsKey(arrayDesign)) {
newprobes.put(arrayDesign, new HashSet<CompositeSequence>());
}
newprobes.get(arrayDesign).add(probe);
dataVectorsThatNeedNewProbes.add(dataVector);
} else {
dataVector.setDesignElement(cachedProbe);
}
}
/*
* Second pass - to fill in vectors that needed probes after the first pass.
*/
if (!dataVectorsThatNeedNewProbes.isEmpty()) {
ExpressionExperimentPrePersistServiceImpl.log.info(dataVectorsThatNeedNewProbes.size() + " vectors don't have probes, may add to the platform.");
newprobes = this.addNewDesignElementToPersistentArrayDesigns(newprobes);
if (newprobes.isEmpty()) {
ExpressionExperimentPrePersistServiceImpl.log.info("No probes were added");
// this is okay if there were none to add, but a problem otherwise.
} else {
// don't forget to cache them.
for (ArrayDesign ad : newprobes.keySet()) {
for (CompositeSequence cs : newprobes.get(ad)) {
cache.addToCache(cs);
}
}
// associate with vectors. This repeats code from above, needs refactoring...
for (DesignElementDataVector v : dataVectorsThatNeedNewProbes) {
CompositeSequence probe = v.getDesignElement();
probe = cache.getFromCache(probe);
if (probe == null || persisterHelper.isTransient(probe)) {
throw new IllegalStateException("All probes should be persistent by now");
}
v.setDesignElement(probe);
}
}
}
return cache;
}
Aggregations