use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.
the class ExpressionExperimentPlatformSwitchService method switchExperimentToArrayDesign.
/**
* If you know the arraydesigns are already in a merged state, you should use switchExperimentToMergedPlatform
*
* @param ee ee
* @param arrayDesign The array design to switch to. If some samples already use that array design, nothing will be
* changed for them.
*/
public ExpressionExperiment switchExperimentToArrayDesign(ExpressionExperiment ee, ArrayDesign arrayDesign) {
assert arrayDesign != null;
// remove stuff that will be in the way.
processedExpressionDataVectorService.removeProcessedDataVectors(ee);
sampleCoexpressionMatrixService.delete(ee);
for (ExpressionExperimentSubSet subset : expressionExperimentService.getSubSets(ee)) {
subsetService.remove(subset);
}
// get relation between sequence and designelements.
Map<BioSequence, Collection<CompositeSequence>> designElementMap = new HashMap<>();
Collection<CompositeSequence> elsWithNoSeq = new HashSet<>();
this.populateCSeq(arrayDesign, designElementMap, elsWithNoSeq);
ee = expressionExperimentService.thaw(ee);
ExpressionExperimentPlatformSwitchService.log.info(elsWithNoSeq.size() + " elements on the new platform have no associated sequence.");
designElementMap.put(ExpressionExperimentPlatformSwitchService.NULL_BIOSEQUENCE, elsWithNoSeq);
boolean multiPlatformPerSample = this.checkMultiPerSample(ee, arrayDesign);
/*
* For a multiplatform-per-sample case: (note that some samples might just be on one platform...)
* 1. Pick a BAD that can be used for all DataVectors (it has all BioAssays in it).
* 2. Switch vectors to use it - may require adding NaNs and reordering the vectors
* 3. Delete the Bioassays that are using other BADs
*/
/*
* Now we have to get the BADs. Problem to watch out for: they might not be the same length, we need one that
* includes all BioMaterials.
*/
Collection<BioAssayDimension> unusedBADs = new HashSet<>();
BioAssayDimension maxBAD = null;
int maxSize = 0;
if (multiPlatformPerSample) {
maxBAD = this.doMultiSample(ee, unusedBADs, maxSize);
}
Collection<ArrayDesign> oldArrayDesigns = expressionExperimentService.getArrayDesignsUsed(ee);
Map<CompositeSequence, Collection<BioAssayDimension>> usedDesignElements = new HashMap<>();
for (ArrayDesign oldAd : oldArrayDesigns) {
this.runOldAd(ee, arrayDesign, designElementMap, maxBAD, usedDesignElements, oldAd);
}
ee.setDescription(ee.getDescription() + " [Switched to use " + arrayDesign.getShortName() + " by Gemma]");
helperService.persist(ee, arrayDesign);
/*
* This might need to be done inside the transaction we're using to make the switch.
*/
if (maxBAD != null && !unusedBADs.isEmpty()) {
this.checkUnused(unusedBADs, maxBAD);
}
return ee;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSubSetDaoImpl method find.
@Override
public ExpressionExperimentSubSet find(ExpressionExperimentSubSet entity) {
Criteria queryObject = this.getSessionFactory().getCurrentSession().createCriteria(ExpressionExperimentSubSet.class);
BusinessKey.checkKey(entity);
BusinessKey.createQueryObject(queryObject, entity);
return (ExpressionExperimentSubSet) queryObject.uniqueResult();
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method checkCache.
/**
* We cache vectors at the experiment level. If we need subsets, we have to slice them out.
*
* @param bioAssaySets that we exactly need the data for.
* @param genes that might have cached results
* @param results from the cache will be put here
* @param needToSearch experiments that need to be searched (not fully cached); this will be populated
* @param genesToSearch that still need to be searched (not in cache)
*/
private void checkCache(Collection<? extends BioAssaySet> bioAssaySets, Collection<Long> genes, Collection<DoubleVectorValueObject> results, Collection<ExpressionExperiment> needToSearch, Collection<Long> genesToSearch) {
for (BioAssaySet ee : bioAssaySets) {
ExpressionExperiment experiment = null;
boolean needSubSet = false;
if (ee instanceof ExpressionExperiment) {
experiment = (ExpressionExperiment) ee;
} else if (ee instanceof ExpressionExperimentSubSet) {
experiment = ((ExpressionExperimentSubSet) ee).getSourceExperiment();
needSubSet = true;
}
assert experiment != null;
for (Long g : genes) {
Collection<DoubleVectorValueObject> obs = processedDataVectorCache.get(ee, g);
if (obs != null) {
if (needSubSet) {
obs = this.sliceSubSet((ExpressionExperimentSubSet) ee, obs);
}
results.addAll(obs);
} else {
genesToSearch.add(g);
}
}
/*
* This experiment is not fully cached for the genes in question.
*/
if (genesToSearch.size() > 0) {
needToSearch.add(experiment);
}
}
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.
the class ProcessedExpressionDataVectorDaoImpl method sliceSubsets.
/**
* @param ees Experiments and/or subsets required
* @param vecs vectors to select from and if necessary slice, obviously from the given ees.
* @return vectors that are for the requested subset. If an ee is not a subset, vectors will be unchanged. Otherwise
* the data in a vector will be for the subset of samples in the ee subset.
*/
private Collection<DoubleVectorValueObject> sliceSubsets(Collection<? extends BioAssaySet> ees, Collection<DoubleVectorValueObject> vecs) {
Collection<DoubleVectorValueObject> results = new HashSet<>();
if (vecs == null || vecs.isEmpty())
return results;
for (BioAssaySet bas : ees) {
if (bas instanceof ExpressionExperimentSubSet) {
for (DoubleVectorValueObject d : vecs) {
if (d.getExpressionExperiment().getId().equals(((ExpressionExperimentSubSet) bas).getSourceExperiment().getId())) {
Collection<DoubleVectorValueObject> ddvos = new HashSet<>();
ddvos.add(d);
// coll
results.addAll(this.sliceSubSet((ExpressionExperimentSubSet) bas, ddvos));
}
}
} else {
for (DoubleVectorValueObject d : vecs) {
if (d.getExpressionExperiment().getId().equals(bas.getId())) {
results.add(d);
}
}
}
}
return results;
}
use of ubic.gemma.model.expression.experiment.ExpressionExperimentSubSet in project Gemma by PavlidisLab.
the class ExpressionExperimentSubSetServiceTest method testFind.
@Test
public final void testFind() {
ExpressionExperiment ee = super.testHelper.getTestPersistentBasicExpressionExperiment();
aclTestUtils.checkEEAcls(ee);
ExpressionExperimentSubSet subset = ExpressionExperimentSubSet.Factory.newInstance();
subset.setSourceExperiment(ee);
subset.getBioAssays().addAll(ee.getBioAssays());
subset.setName("foo");
ExpressionExperimentSubSet persisted = expressionExperimentSubSetService.create(subset);
assertNotNull(persisted);
aclTestUtils.checkEESubSetAcls(persisted);
ExpressionExperimentSubSet hit = expressionExperimentSubSetService.find(persisted);
assertEquals(persisted, hit);
}
Aggregations