use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.
the class ArrayDesignPersister method findOrPersistArrayDesign.
/**
* Persist an array design.
*/
private ArrayDesign findOrPersistArrayDesign(ArrayDesign arrayDesign) {
if (arrayDesign == null)
return null;
if (!this.isTransient(arrayDesign))
return arrayDesign;
/*
* Note we don't do a full find here.
*/
ArrayDesign existing = arrayDesignDao.find(arrayDesign);
if (existing == null) {
/*
* Try less stringent search.
*/
existing = arrayDesignDao.findByShortName(arrayDesign.getShortName());
if (existing == null) {
AbstractPersister.log.info(arrayDesign + " is new, processing...");
return this.persistNewArrayDesign(arrayDesign);
}
AbstractPersister.log.info("Platform exactly matching " + arrayDesign + " doesn't exist, but found " + existing + "; returning");
} else {
AbstractPersister.log.info("Platform " + arrayDesign + " already exists, returning...");
}
return existing;
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesign 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);
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.
the class ExpressionDataFileUploadController method doValidate.
private SimpleExpressionExperimentCommandValidation doValidate(SimpleExpressionExperimentLoadTaskCommand command) {
this.scrub(command);
ExpressionExperiment existing = expressionExperimentService.findByShortName(command.getShortName());
SimpleExpressionExperimentCommandValidation result = new SimpleExpressionExperimentCommandValidation();
ExpressionDataFileUploadController.log.info("Checking for valid name and files");
result.setShortNameIsUnique(existing == null);
String localPath = command.getServerFilePath();
if (StringUtils.isBlank(localPath)) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("File is missing");
return result;
}
File file = new File(localPath);
if (!file.canRead()) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("Cannot read from file");
return result;
}
Collection<Long> arrayDesignIds = command.getArrayDesignIds();
if (arrayDesignIds.isEmpty()) {
result.setArrayDesignMatchesDataFile(false);
result.setArrayDesignMismatchProblemMessage("Platform must be provided");
return result;
}
DoubleMatrix<String, String> parse = null;
try {
parse = simpleExpressionDataLoaderService.parse(FileTools.getInputStreamFromPlainOrCompressedFile(file.getAbsolutePath()));
} catch (FileNotFoundException e) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("File is missing");
} catch (IOException e) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("File is invalid: " + e.getMessage());
} catch (IllegalArgumentException e) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("File is invalid: " + e.getMessage());
} catch (Exception e) {
result.setDataFileIsValidFormat(false);
result.setDataFileFormatProblemMessage("Error Validating: " + e.getMessage());
}
if (parse != null) {
ExpressionDataFileUploadController.log.info("Checking if probe labels match design");
result.setNumRows(parse.rows());
result.setNumColumns(parse.columns());
Long arrayDesignId = arrayDesignIds.iterator().next();
ArrayDesign design = arrayDesignService.load(arrayDesignId);
design = arrayDesignService.thaw(design);
// check that the probes can be matched up...
int numRowsMatchingArrayDesign = 0;
int numRowsNotMatchingArrayDesign = 0;
int i = 0;
List<String> mismatches = new ArrayList<>();
for (CompositeSequence cs : design.getCompositeSequences()) {
if (parse.containsRowName(cs.getName())) {
numRowsMatchingArrayDesign++;
} else {
numRowsNotMatchingArrayDesign++;
mismatches.add(cs.getName());
}
if (++i % 2000 == 0) {
ExpressionDataFileUploadController.log.info(i + " probes checked, " + numRowsMatchingArrayDesign + " match");
}
}
result.setNumberMatchingProbes(numRowsMatchingArrayDesign);
result.setNumberOfNonMatchingProbes(numRowsNotMatchingArrayDesign);
if (mismatches.size() > 0) {
result.setNonMatchingProbeNameExamples(mismatches.subList(0, Math.min(10, mismatches.size() - 1)));
}
}
return result;
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.
the class ArrayDesignProbeMapperController method run.
/**
* AJAX entry point.
*/
public String run(Long id) {
ArrayDesign arrayDesign = arrayDesignService.load(id);
arrayDesign = arrayDesignService.thaw(arrayDesign);
ArrayDesignProbeMapTaskCommand cmd = new ArrayDesignProbeMapTaskCommand();
cmd.setArrayDesign(arrayDesign);
return taskRunningService.submitRemoteTask(cmd);
}
use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.
the class ExpressionDataFileServiceImpl method getGeneAnnotationsAsStringsByProbe.
private Map<CompositeSequence, String[]> getGeneAnnotationsAsStringsByProbe(Collection<ArrayDesign> ads) {
Map<CompositeSequence, String[]> annotations = new HashMap<>();
for (ArrayDesign arrayDesign : ads) {
arrayDesign = arrayDesignService.thaw(arrayDesign);
Map<Long, CompositeSequence> csIdMap = EntityUtils.getIdMap(arrayDesign.getCompositeSequences());
Map<Long, String[]> geneAnnotations = ArrayDesignAnnotationServiceImpl.readAnnotationFileAsString(arrayDesign);
for (Entry<Long, String[]> e : geneAnnotations.entrySet()) {
if (!csIdMap.containsKey(e.getKey())) {
continue;
}
annotations.put(csIdMap.get(e.getKey()), e.getValue());
}
}
return annotations;
}
Aggregations