use of ubic.gemma.persistence.util.ArrayDesignsForExperimentCache in project Gemma by PavlidisLab.
the class PersistentDummyObjectHelper method getTestExpressionExperimentWithAllDependencies.
public ExpressionExperiment getTestExpressionExperimentWithAllDependencies(ExpressionExperiment prototype) {
ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
ee.setShortName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
ee.setName("Expression Experiment " + RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
ee.setDescription("A test expression experiment");
ee.setSource("https://www.ncbi.nlm.nih.gov/geo/");
DatabaseEntry de1 = this.getTestPersistentDatabaseEntry(PersistentDummyObjectHelper.geo);
ee.setAccession(de1);
LocalFile file = LocalFile.Factory.newInstance();
try {
file.setLocalURL(new URL("file:///just/a/placeholder/" + ee.getShortName()));
} catch (MalformedURLException e) {
log.error("Malformed URL");
}
ee.setRawDataFile(file);
Collection<FactorValue> allFactorValues = new HashSet<>();
ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
Collection<BioMaterial> bioMaterials = this.getBioMaterials(allFactorValues);
ee.setExperimentalDesign(ed);
ee.setOwner(this.getTestPersistentContact());
List<ArrayDesign> arrayDesignsUsed = new ArrayList<>(eeService.getArrayDesignsUsed(prototype));
Collection<BioAssay> bioAssays = new HashSet<>();
Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
eeService.thaw(prototype);
Collection<RawExpressionDataVector> vectors = new HashSet<>();
for (ArrayDesign ad : arrayDesignsUsed) {
List<BioAssay> bas = this.getBioAssays(bioMaterials, ad);
bioAssays.addAll(bas);
ad = this.adService.thaw(ad);
vectors.addAll(this.getDesignElementDataVectors(ee, quantitationTypes, bas, ad));
}
ee.setBioAssays(bioAssays);
assert quantitationTypes.size() > 0;
ee.setQuantitationTypes(quantitationTypes);
ee.setRawExpressionDataVectors(vectors);
ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
ee = persisterHelper.persist(ee, c);
return ee;
}
use of ubic.gemma.persistence.util.ArrayDesignsForExperimentCache in project Gemma by PavlidisLab.
the class PersistentDummyObjectHelper method getTestExpressionExperimentWithAllDependencies.
/**
* Add an expressionExperiment to the database for testing purposes. Includes associations
*
* @param doSequence Should the array design get all the sequence information filled in? (true = slower)
* @return EE
*/
public ExpressionExperiment getTestExpressionExperimentWithAllDependencies(boolean doSequence) {
ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
ee.setShortName(RandomStringUtils.randomAlphanumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
ee.setName("Expression Experiment " + RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH));
ee.setDescription("A test expression experiment");
ee.setSource("https://www.ncbi.nlm.nih.gov/geo/");
DatabaseEntry de1 = this.getTestPersistentDatabaseEntry(PersistentDummyObjectHelper.geo);
ee.setAccession(de1);
LocalFile file = LocalFile.Factory.newInstance();
try {
file.setLocalURL(new URL("file:///just/a/placeholder/" + ee.getShortName()));
} catch (MalformedURLException e) {
log.error("Malformed URL");
}
ee.setRawDataFile(file);
ArrayDesign adA = this.getTestPersistentArrayDesign(this.getTestElementCollectionSize(), false, doSequence);
ArrayDesign adB = this.getTestPersistentArrayDesign(this.getTestElementCollectionSize(), false, doSequence);
Collection<FactorValue> allFactorValues = new HashSet<>();
ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
ee.setExperimentalDesign(ed);
ee.setOwner(this.getTestPersistentContact());
Collection<BioAssay> bioAssays = new HashSet<>();
Collection<BioMaterial> bioMaterials = this.getBioMaterials(allFactorValues);
List<BioAssay> bioAssaysA = this.getBioAssays(bioMaterials, adA);
List<BioAssay> bioAssaysB = this.getBioAssays(bioMaterials, adB);
bioAssays.addAll(bioAssaysA);
bioAssays.addAll(bioAssaysB);
ee.setBioAssays(bioAssays);
log.debug("expression experiment => design element data vectors");
Collection<RawExpressionDataVector> vectors = new HashSet<>();
Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
assert quantitationTypes.size() > 0;
vectors.addAll(this.getDesignElementDataVectors(ee, quantitationTypes, bioAssaysA, adA));
vectors.addAll(this.getDesignElementDataVectors(ee, quantitationTypes, bioAssaysB, adB));
ee.setQuantitationTypes(quantitationTypes);
ee.setRawExpressionDataVectors(vectors);
ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
ee = persisterHelper.persist(ee, c);
return ee;
}
use of ubic.gemma.persistence.util.ArrayDesignsForExperimentCache in project Gemma by PavlidisLab.
the class GeoServiceImpl method fetchAndLoad.
/**
* Given a GEO GSE or GDS (or GPL, but support might not be complete)
* <ol>
* <li>Check that it doesn't already exist in the system</li>
* <li>Download and parse GDS files and GSE file needed</li>
* <li>Convert the GDS and GSE into a ExpressionExperiment (or just the ArrayDesigns)
* <li>Load the resulting ExpressionExperiment and/or ArrayDesigns into Gemma</li>
* </ol>
*/
@Override
public Collection<?> fetchAndLoad(String geoAccession, boolean loadPlatformOnly, boolean doSampleMatching, boolean splitByPlatform, boolean allowSuperSeriesImport, boolean allowSubSeriesImport) {
/*
* We do this to get a fresh instantiation of GeoConverter (prototype scope)
*/
GeoConverter geoConverter = (GeoConverter) this.beanFactory.getBean("geoConverter");
if (this.geoDomainObjectGenerator == null) {
this.geoDomainObjectGenerator = new GeoDomainObjectGenerator();
} else {
this.geoDomainObjectGenerator.initialize();
}
geoDomainObjectGenerator.setProcessPlatformsOnly(geoAccession.startsWith("GPL") || loadPlatformOnly);
geoDomainObjectGenerator.setDoSampleMatching(doSampleMatching && !splitByPlatform);
Collection<DatabaseEntry> projectedAccessions = geoDomainObjectGenerator.getProjectedAccessions(geoAccession);
this.checkForExisting(projectedAccessions);
if (loadPlatformOnly) {
Collection<? extends GeoData> platforms = geoDomainObjectGenerator.generate(geoAccession);
if (platforms.size() == 0) {
AbstractGeoService.log.warn("GeoService.fetchAndLoad( targetPlatformAcc, true, false, false, false );t no results");
return null;
}
geoConverter.setForceConvertElements(true);
Collection<Object> arrayDesigns = geoConverter.convert(platforms);
return persisterHelper.persist(arrayDesigns);
}
Collection<? extends GeoData> parseResult = geoDomainObjectGenerator.generate(geoAccession);
if (parseResult.size() == 0) {
AbstractGeoService.log.warn("Got no results");
return null;
}
AbstractGeoService.log.debug("Generated GEO domain objects for " + geoAccession);
Object obj = parseResult.iterator().next();
if (!(obj instanceof GeoSeries)) {
throw new RuntimeException("Got a " + obj.getClass().getName() + " instead of a " + GeoSeries.class.getName() + " (you may need to load platforms only).");
}
GeoSeries series = (GeoSeries) obj;
String seriesAccession = series.getGeoAccession();
if (series.isSuperSeries()) {
if (allowSuperSeriesImport) {
AbstractGeoService.log.info(" ========= SuperSeries Detected! =========");
AbstractGeoService.log.info("Please make sure you want to import this as a superseries and not the individual subseries");
} else {
throw new IllegalStateException("SuperSeries detected, set 'allowSuperSeriesImport' to 'true' to allow this dataset to load");
}
}
if (series.isSubSeries()) {
if (allowSubSeriesImport) {
AbstractGeoService.log.info(" ========= Subseries Detected! =========");
AbstractGeoService.log.info("Please make sure you want to import this as a subseries and not the superseries");
} else {
throw new IllegalStateException("SubSeries detected, set 'allowSubSeriesImport' to 'true' to allow this dataset to load");
}
}
this.confirmPlatformUniqueness(series, doSampleMatching && !splitByPlatform);
ArrayDesignsForExperimentCache c = new ArrayDesignsForExperimentCache();
this.matchToExistingPlatforms(geoConverter, series, c);
this.checkSamplesAreNew(series);
this.getSubSeriesInformation(series);
geoConverter.clear();
geoConverter.setSplitByPlatform(splitByPlatform);
// noinspection unchecked
Collection<ExpressionExperiment> result = (Collection<ExpressionExperiment>) geoConverter.convert(series);
this.check(result);
this.getPubMedInfo(result);
AbstractGeoService.log.debug("Converted " + seriesAccession);
assert persisterHelper != null;
Collection<ExpressionExperiment> persistedResult = new HashSet<>();
for (ExpressionExperiment ee : result) {
c = expressionExperimentPrePersistService.prepare(ee, c);
ee = persisterHelper.persist(ee, c);
persistedResult.add(ee);
AbstractGeoService.log.debug("Persisted " + seriesAccession);
}
this.updateReports(persistedResult);
return persistedResult;
}
use of ubic.gemma.persistence.util.ArrayDesignsForExperimentCache in project Gemma by PavlidisLab.
the class PersistentDummyObjectHelper method getTestPersistentExpressionExperiment.
/**
* Convenience method to provide an ExpressionExperiment that can be used to fill non-nullable associations in test
* objects. This implementation does NOT fill in associations of the created object except for the creation of
* persistent BioMaterials and BioAssays so that database taxon lookups for this experiment will work.
*
* @param taxon the experiment will have this taxon
* @return EE
*/
public ExpressionExperiment getTestPersistentExpressionExperiment(Taxon taxon) {
BioAssay ba;
BioMaterial bm;
ArrayDesign ad;
bm = this.getTestPersistentBioMaterial(taxon);
ad = this.getTestPersistentArrayDesign(4, true, true);
ba = this.getTestPersistentBioAssay(ad, bm);
Set<BioAssay> bas1 = new HashSet<>();
bas1.add(ba);
ExpressionExperiment ee = ExpressionExperiment.Factory.newInstance();
ee.setName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
ee.setShortName(RandomStringUtils.randomNumeric(PersistentDummyObjectHelper.RANDOM_STRING_LENGTH) + "_testee");
ee.setBioAssays(bas1);
Collection<FactorValue> allFactorValues = new HashSet<>();
ExperimentalDesign ed = this.getExperimentalDesign(allFactorValues);
ee.setExperimentalDesign(ed);
ee.setOwner(this.getTestPersistentContact());
log.debug("expression experiment => design element data vectors");
Collection<RawExpressionDataVector> vectors = new HashSet<>();
Collection<QuantitationType> quantitationTypes = this.addQuantitationTypes(new HashSet<QuantitationType>());
assert quantitationTypes.size() > 0;
ee.setQuantitationTypes(quantitationTypes);
ee.setRawExpressionDataVectors(vectors);
ArrayDesignsForExperimentCache c = persisterHelper.prepare(ee);
return persisterHelper.persist(ee, c);
}
use of ubic.gemma.persistence.util.ArrayDesignsForExperimentCache in project Gemma by PavlidisLab.
the class ExpressionPersister method persist.
@Override
public Object persist(Object entity) {
if (entity == null)
return null;
if (entity instanceof ExpressionExperiment) {
AbstractPersister.log.warn("Consider doing the 'setup' step in a separate transaction");
this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
ArrayDesignsForExperimentCache c = expressionExperimentPrePersistService.prepare((ExpressionExperiment) entity);
return this.persist((ExpressionExperiment) entity, c);
} else if (entity instanceof BioAssayDimension) {
return this.persistBioAssayDimension((BioAssayDimension) entity, null);
} else if (entity instanceof BioMaterial) {
return this.persistBioMaterial((BioMaterial) entity);
} else if (entity instanceof BioAssay) {
return this.persistBioAssay((BioAssay) entity, null);
} else if (entity instanceof Compound) {
return this.persistCompound((Compound) entity);
} else if (entity instanceof ExpressionExperimentSubSet) {
return this.persistExpressionExperimentSubSet((ExpressionExperimentSubSet) entity);
}
return super.persist(entity);
}
Aggregations