Search in sources :

Example 86 with ArrayDesign

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;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign)

Example 87 with ArrayDesign

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);
}
Also used : BioMaterial(ubic.gemma.model.expression.biomaterial.BioMaterial) LocalFile(ubic.gemma.model.common.description.LocalFile) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign)

Example 88 with ArrayDesign

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;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) PreprocessingException(ubic.gemma.core.analysis.preprocess.PreprocessingException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) File(java.io.File)

Example 89 with ArrayDesign

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);
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ArrayDesignProbeMapTaskCommand(ubic.gemma.core.tasks.analysis.sequence.ArrayDesignProbeMapTaskCommand)

Example 90 with ArrayDesign

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;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence)

Aggregations

ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)186 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)43 Test (org.junit.Test)32 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)26 InputStream (java.io.InputStream)25 BioAssay (ubic.gemma.model.expression.bioAssay.BioAssay)24 BioSequence (ubic.gemma.model.genome.biosequence.BioSequence)24 Taxon (ubic.gemma.model.genome.Taxon)23 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)19 HashSet (java.util.HashSet)16 RawExpressionDataVector (ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector)16 Collection (java.util.Collection)14 AbstractGeoServiceTest (ubic.gemma.core.loader.expression.geo.AbstractGeoServiceTest)13 StopWatch (org.apache.commons.lang3.time.StopWatch)12 Before (org.junit.Before)12 BioMaterial (ubic.gemma.model.expression.biomaterial.BioMaterial)12 BioAssayDimension (ubic.gemma.model.expression.bioAssayData.BioAssayDimension)9 GZIPInputStream (java.util.zip.GZIPInputStream)8 SimpleExpressionExperimentMetaData (ubic.gemma.core.loader.expression.simple.model.SimpleExpressionExperimentMetaData)8 File (java.io.File)7