use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class LocalFileDaoImpl method find.
@Override
public LocalFile find(LocalFile localFile) {
BusinessKey.checkValidKey(localFile);
HibernateTemplate t = new HibernateTemplate(this.getSessionFactory());
t.setFlushMode(HibernateAccessor.FLUSH_COMMIT);
List<?> results;
if (localFile.getRemoteURL() == null) {
results = t.findByNamedParam("from LocalFile where localURL=:u and remoteURL is null ", "u", localFile.getLocalURL());
} else if (localFile.getLocalURL() == null) {
results = t.findByNamedParam("from LocalFile where localURL is null and remoteURL=:r", "r", localFile.getRemoteURL());
} else {
results = t.findByNamedParam("from LocalFile where localURL=:u and remoteURL=:r", new String[] { "u", "r" }, new Object[] { localFile.getLocalURL(), localFile.getRemoteURL() });
}
Object result = null;
if (results != null) {
if (results.size() > 1) {
throw new org.springframework.dao.InvalidDataAccessResourceUsageException("More than one instance of '" + LocalFile.class.getName() + "' was found when executing query");
} else if (results.size() == 1) {
result = results.get(0);
}
}
return (LocalFile) result;
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class LocalFileServiceImpl method deleteFile.
/**
* @see LocalFileService#deleteFile(ubic.gemma.model.common.description.LocalFile)
*/
@Override
public void deleteFile(LocalFile localFile) throws IOException {
if (localFile == null)
return;
File file = localFile.asFile();
if (file == null)
throw new IOException("Could not convert LocalFile into java.io.File");
boolean success = false;
if (file.exists()) {
success = file.delete();
}
if (file.exists() || !success) {
throw new IOException("Cannot remove file");
}
this.localFileDao.remove(localFile);
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class DataUpdater method addAffyExonArrayData.
/**
* Replaces any existing "preferred" data. Must be a single-platform study
*
* @param ee ee
* @param ad ad
*/
// Possible external use
@SuppressWarnings({ "unused", "WeakerAccess" })
public void addAffyExonArrayData(ExpressionExperiment ee, ArrayDesign ad) {
RawDataFetcher f = new RawDataFetcher();
Collection<LocalFile> files = f.fetch(ee.getAccession().getAccession());
if (files.isEmpty()) {
throw new RuntimeException("Data was apparently not available");
}
ad = arrayDesignService.thaw(ad);
ee = experimentService.thawLite(ee);
Taxon primaryTaxon = ad.getPrimaryTaxon();
ArrayDesign targetPlatform = this.prepareTargetPlatformForExonArrays(primaryTaxon);
assert !targetPlatform.getCompositeSequences().isEmpty();
AffyPowerToolsProbesetSummarize apt = new AffyPowerToolsProbesetSummarize();
Collection<RawExpressionDataVector> vectors = apt.processExonArrayData(ee, targetPlatform, files);
if (vectors.isEmpty()) {
throw new IllegalStateException("No vectors were returned for " + ee);
}
ee = experimentService.replaceRawVectors(ee, vectors);
if (!targetPlatform.equals(ad)) {
AuditEventType eventType = ExpressionExperimentPlatformSwitchEvent.Factory.newInstance();
auditTrailService.addUpdateEvent(ee, eventType, "Switched in course of updating vectors using AffyPowerTools (from " + ad.getShortName() + " to " + targetPlatform.getShortName() + ")");
}
this.audit(ee, "Data vector computation from CEL files using AffyPowerTools for " + targetPlatform, true);
this.postprocess(ee);
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class ArrayDesignPersister method persistNewArrayDesign.
/**
* Persist an entirely new array design, including composite sequences and any associated new sequences.
*/
private ArrayDesign persistNewArrayDesign(ArrayDesign arrayDesign) {
if (arrayDesign == null)
return null;
AbstractPersister.log.info("Persisting new platform " + arrayDesign.getName());
try {
this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.COMMIT);
if (arrayDesign.getDesignProvider() != null)
arrayDesign.setDesignProvider(this.persistContact(arrayDesign.getDesignProvider()));
if (arrayDesign.getLocalFiles() != null) {
for (LocalFile file : arrayDesign.getLocalFiles()) {
this.persistLocalFile(file);
}
}
if (arrayDesign.getPrimaryTaxon() == null) {
throw new IllegalArgumentException("Primary taxon cannot be null");
}
arrayDesign.setPrimaryTaxon((Taxon) this.persist(arrayDesign.getPrimaryTaxon()));
for (DatabaseEntry externalRef : arrayDesign.getExternalReferences()) {
externalRef.setExternalDatabase(this.persistExternalDatabase(externalRef.getExternalDatabase()));
}
AbstractPersister.log.info("Persisting " + arrayDesign);
if (arrayDesign.getAuditTrail() != null && this.isTransient(arrayDesign.getAuditTrail()))
arrayDesign.getAuditTrail().setId(null);
Collection<CompositeSequence> scs = new ArrayList<>(arrayDesign.getCompositeSequences());
arrayDesign.getCompositeSequences().clear();
arrayDesign = arrayDesignDao.create(arrayDesign);
arrayDesign.getCompositeSequences().addAll(scs);
arrayDesign = this.persistArrayDesignCompositeSequenceAssociations(arrayDesign);
arrayDesignDao.update(arrayDesign);
} finally {
this.getSessionFactory().getCurrentSession().setFlushMode(FlushMode.AUTO);
}
return arrayDesign;
}
use of ubic.gemma.model.common.description.LocalFile in project Gemma by PavlidisLab.
the class ExpressionPersister method fillInBioAssayAssociations.
private void fillInBioAssayAssociations(BioAssay bioAssay, ArrayDesignsForExperimentCache c) {
ArrayDesign arrayDesign = bioAssay.getArrayDesignUsed();
ArrayDesign arrayDesignUsed;
if (!this.isTransient(arrayDesign)) {
arrayDesignUsed = arrayDesign;
} else if (c == null || !c.getArrayDesignCache().containsKey(arrayDesign.getShortName())) {
throw new UnsupportedOperationException("You must provide the persistent platforms in a cache object");
} else {
arrayDesignUsed = c.getArrayDesignCache().get(arrayDesign.getShortName());
if (arrayDesignUsed == null || arrayDesignUsed.getId() == null) {
throw new IllegalStateException("You must provide the platform in the cache object");
}
arrayDesignUsed = (ArrayDesign) this.getSessionFactory().getCurrentSession().load(ArrayDesign.class, arrayDesignUsed.getId());
if (arrayDesignUsed == null) {
throw new IllegalStateException("No platform matching " + arrayDesign.getShortName());
}
AbstractPersister.log.debug("Setting platform used for bioassay to " + arrayDesignUsed.getId());
}
assert !this.isTransient(arrayDesignUsed);
bioAssay.setArrayDesignUsed(arrayDesignUsed);
boolean hadFactors = false;
BioMaterial material = bioAssay.getSampleUsed();
for (FactorValue factorValue : material.getFactorValues()) {
// Factors are not compositioned in any more, but by association with the ExperimentalFactor.
this.fillInFactorValueAssociations(factorValue);
this.persistFactorValue(factorValue);
hadFactors = true;
}
if (hadFactors)
AbstractPersister.log.debug("factor values done");
// DatabaseEntries are persisted by composition, so we just need to fill in the ExternalDatabase.
if (bioAssay.getAccession() != null) {
bioAssay.getAccession().setExternalDatabase(this.persistExternalDatabase(bioAssay.getAccession().getExternalDatabase()));
// IN CASE we are retrying.
bioAssay.getAccession().setId(null);
AbstractPersister.log.debug("external database done");
}
// BioMaterials
bioAssay.setSampleUsed((BioMaterial) this.persist(bioAssay.getSampleUsed()));
AbstractPersister.log.debug("biomaterials done");
LocalFile rawDataFile = bioAssay.getRawDataFile();
if (rawDataFile != null) {
if (this.isTransient(rawDataFile)) {
// in case of retry.
rawDataFile.setId(null);
// raw file is unique for bioassay.
bioAssay.setRawDataFile(this.persistLocalFile(rawDataFile, true));
} else {
// re-sync.
this.localFileDao.update(rawDataFile);
}
AbstractPersister.log.debug("raw data file done");
}
for (LocalFile file : bioAssay.getDerivedDataFiles()) {
if (this.isTransient(file))
// in case of retry
file.setId(null);
this.persistLocalFile(file);
}
if (this.isTransient(bioAssay.getAuditTrail()) && bioAssay.getAuditTrail() != null)
// in case of retry;
bioAssay.getAuditTrail().setId(null);
AbstractPersister.log.debug("Done with " + bioAssay);
}
Aggregations