Search in sources :

Example 66 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class GeoServiceImpl method addElements.

@Override
public ArrayDesign addElements(ArrayDesign targetPlatform) {
    if (!targetPlatform.getCompositeSequences().isEmpty()) {
        throw new IllegalArgumentException("Only call this if you are filling in an empty platform");
    }
    String geoAccession = targetPlatform.getExternalReferences().iterator().next().getAccession();
    Collection<? extends GeoData> platforms = geoDomainObjectGenerator.generate(geoAccession);
    if (platforms.size() == 0) {
        throw new IllegalStateException();
    }
    /*
         * 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(true);
    geoConverter.setForceConvertElements(true);
    Collection<Object> arrayDesigns = geoConverter.convert(platforms);
    Collection<CompositeSequence> els = ((ArrayDesign) arrayDesigns.iterator().next()).getCompositeSequences();
    for (CompositeSequence cs : els) {
        cs.setArrayDesign(targetPlatform);
        cs.setBiologicalCharacteristic((BioSequence) persisterHelper.persist(cs.getBiologicalCharacteristic()));
    }
    AbstractGeoService.log.info("Adding " + els.size() + " elements to " + targetPlatform);
    targetPlatform.getCompositeSequences().addAll(els);
    arrayDesignService.update(targetPlatform);
    this.arrayDesignReportService.generateArrayDesignReport(targetPlatform.getId());
    return targetPlatform;
}
Also used : GeoDomainObjectGenerator(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) CompositeSequence(ubic.gemma.model.expression.designElement.CompositeSequence) GeoConverter(ubic.gemma.core.loader.expression.geo.GeoConverter)

Example 67 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class GeoConverterImpl method createMinimalArrayDesign.

private ArrayDesign createMinimalArrayDesign(GeoPlatform platform) {
    ArrayDesign arrayDesign = ArrayDesign.Factory.newInstance();
    arrayDesign.setName(platform.getTitle());
    arrayDesign.setShortName(platform.getGeoAccession());
    arrayDesign.setDescription(platform.getDescriptions());
    PlatformType technology = platform.getTechnology();
    if (technology == PlatformType.dualChannel || technology == PlatformType.dualChannelGenomic || technology == PlatformType.spottedOligonucleotide || technology == PlatformType.spottedDNAOrcDNA) {
        arrayDesign.setTechnologyType(TechnologyType.TWOCOLOR);
    } else if (technology == PlatformType.singleChannel || technology == PlatformType.oligonucleotideBeads || technology == PlatformType.inSituOligonucleotide) {
        arrayDesign.setTechnologyType(TechnologyType.ONECOLOR);
    } else if (technology == null) {
        GeoConverterImpl.log.warn("No technology type available for " + platform + ", provisionally setting to 'dual mode'");
        arrayDesign.setTechnologyType(TechnologyType.DUALMODE);
    } else if (technology.equals(PlatformType.MPSS)) {
        // we don't support this directly
        arrayDesign.setTechnologyType(TechnologyType.NONE);
    } else if (technology.equals(PlatformType.SAGE) || technology.equals(PlatformType.SAGENlaIII) || technology.equals(PlatformType.SAGERsaI) || technology.equals(PlatformType.SAGESau3A) || technology.equals(PlatformType.other)) {
        // we don't support this directly
        arrayDesign.setTechnologyType(TechnologyType.NONE);
    } else {
        throw new IllegalArgumentException("Don't know how to interpret technology type " + technology);
    }
    return arrayDesign;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) PlatformType(ubic.gemma.core.loader.expression.geo.model.GeoDataset.PlatformType)

Example 68 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceImpl method addRawVectors.

@Override
@Transactional
public ExpressionExperiment addRawVectors(ExpressionExperiment ee, Collection<RawExpressionDataVector> newVectors) {
    Collection<BioAssayDimension> BADs = new HashSet<>();
    Collection<QuantitationType> qts = new HashSet<>();
    for (RawExpressionDataVector vec : newVectors) {
        BADs.add(vec.getBioAssayDimension());
        qts.add(vec.getQuantitationType());
    }
    if (BADs.size() > 1) {
        throw new IllegalArgumentException("Vectors must share a common bioassay dimension");
    }
    if (qts.size() > 1) {
        throw new UnsupportedOperationException("Can only replace with one type of vector (only one quantitation type)");
    }
    BioAssayDimension bad = BADs.iterator().next();
    bad = this.bioAssayDimensionService.findOrCreate(bad);
    assert bad.getBioAssays().size() > 0;
    QuantitationType newQt = qts.iterator().next();
    if (newQt.getId() == null) {
        newQt = this.quantitationTypeDao.create(newQt);
    } else {
        AbstractService.log.warn("Quantitation type already had an ID...:" + newQt);
    }
    /*
         * This is probably a more or less redundant setting, but doesn't hurt to make sure.
         */
    ArrayDesign vectorAd = newVectors.iterator().next().getDesignElement().getArrayDesign();
    for (BioAssay ba : bad.getBioAssays()) {
        ba.setArrayDesignUsed(vectorAd);
    }
    for (RawExpressionDataVector vec : newVectors) {
        vec.setBioAssayDimension(bad);
        vec.setQuantitationType(newQt);
    }
    ee = rawExpressionDataVectorDao.addVectors(ee.getId(), newVectors);
    // this is a denormalization; easy to forget to update this.
    ee.getQuantitationTypes().add(newQt);
    AbstractService.log.info(ee.getRawExpressionDataVectors().size() + " vectors for experiment");
    return ee;
}
Also used : BioAssayDimension(ubic.gemma.model.expression.bioAssayData.BioAssayDimension) RawExpressionDataVector(ubic.gemma.model.expression.bioAssayData.RawExpressionDataVector) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) QuantitationType(ubic.gemma.model.common.quantitationtype.QuantitationType) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class DesignElementDataVectorDaoImpl method thaw.

@Override
public void thaw(T designElementDataVector) {
    Session session = this.getHibernateTemplate().getSessionFactory().getCurrentSession();
    BioSequence seq = designElementDataVector.getDesignElement().getBiologicalCharacteristic();
    if (seq != null) {
        session.buildLockRequest(LockOptions.NONE).lock(seq);
        Hibernate.initialize(seq);
    }
    ArrayDesign arrayDesign = designElementDataVector.getDesignElement().getArrayDesign();
    Hibernate.initialize(arrayDesign);
    // thawRawAndProcessed the bioassays.
    for (BioAssay ba : designElementDataVector.getBioAssayDimension().getBioAssays()) {
        ba = (BioAssay) session.get(BioAssay.class, ba.getId());
        Hibernate.initialize(ba.getArrayDesignUsed());
        Hibernate.initialize(ba.getSampleUsed());
        Hibernate.initialize(ba.getDerivedDataFiles());
    }
}
Also used : BioSequence(ubic.gemma.model.genome.biosequence.BioSequence) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) BioAssay(ubic.gemma.model.expression.bioAssay.BioAssay)

Example 70 with ArrayDesign

use of ubic.gemma.model.expression.arrayDesign.ArrayDesign in project Gemma by PavlidisLab.

the class ProcessedExpressionDataVectorDaoImpl method handleGetProcessedExpressionDataArrays.

/**
 * This is an important method for fetching vectors.
 *
 * @param genes genes
 * @param ees   ees
 * @return vectors, possibly subsetted.
 */
private Collection<DoubleVectorValueObject> handleGetProcessedExpressionDataArrays(Collection<? extends BioAssaySet> ees, Collection<Long> genes) {
    // ees must be thawed first as currently implemented (?)
    Collection<DoubleVectorValueObject> results = new HashSet<>();
    /*
         * Check the cache.
         */
    Collection<ExpressionExperiment> needToSearch = new HashSet<>();
    Collection<Long> genesToSearch = new HashSet<>();
    this.checkCache(ees, genes, results, needToSearch, genesToSearch);
    AbstractDao.log.info("Using " + results.size() + " DoubleVectorValueObject(s) from cache");
    if (needToSearch.size() == 0) {
        return results;
    }
    /*
         * Get items not in the cache.
         */
    AbstractDao.log.info("Searching for vectors for " + genes.size() + " genes from " + needToSearch.size() + " experiments not in cache");
    Collection<ArrayDesign> arrays = CommonQueries.getArrayDesignsUsed(EntityUtils.getIds(this.getExperiments(ees)), this.getSessionFactory().getCurrentSession()).keySet();
    assert !arrays.isEmpty();
    Map<Long, Collection<Long>> cs2gene = CommonQueries.getCs2GeneIdMap(genesToSearch, EntityUtils.getIds(arrays), this.getSessionFactory().getCurrentSession());
    if (cs2gene.size() == 0) {
        if (results.isEmpty()) {
            AbstractDao.log.warn("No composite sequences found for genes");
            return new HashSet<>();
        }
        return results;
    }
    /*
         * Fill in the map, because we want to track information on the specificity of the probes used in the data
         * vectors.
         */
    cs2gene = CommonQueries.getCs2GeneMapForProbes(cs2gene.keySet(), this.getSessionFactory().getCurrentSession());
    Map<ProcessedExpressionDataVector, Collection<Long>> processedDataVectors = this.getProcessedVectors(EntityUtils.getIds(needToSearch), cs2gene);
    Map<BioAssaySet, Collection<BioAssayDimension>> bioAssayDimensions = this.getBioAssayDimensions(needToSearch);
    Collection<DoubleVectorValueObject> newResults = new HashSet<>();
    /*
         * This loop is to ensure that we don't get misaligned vectors for experiments that use more than one array
         * design. See bug 1704. This isn't that common, so we try to break out as soon as possible.
         */
    for (BioAssaySet bas : needToSearch) {
        Collection<BioAssayDimension> dims = bioAssayDimensions.get(bas);
        if (dims == null || dims.isEmpty()) {
            AbstractDao.log.warn("BioAssayDimensions were null/empty unexpectedly.");
            continue;
        }
        /*
             * Get the vectors for just this experiment. This is made more efficient by removing things from the map
             * each time through.
             */
        Map<ProcessedExpressionDataVector, Collection<Long>> vecsForBas = new HashMap<>();
        if (needToSearch.size() == 1) {
            vecsForBas = processedDataVectors;
        } else {
            // isolate the vectors for the current experiment.
            for (Iterator<ProcessedExpressionDataVector> it = processedDataVectors.keySet().iterator(); it.hasNext(); ) {
                ProcessedExpressionDataVector v = it.next();
                if (v.getExpressionExperiment().equals(bas)) {
                    vecsForBas.put(v, processedDataVectors.get(v));
                    // since we're done with it.
                    it.remove();
                }
            }
        }
        /*
             * Now see if anything is 'ragged' (fewer bioassays per biomaterial than in some other vector)
             */
        if (dims.size() == 1) {
            newResults.addAll(this.unpack(vecsForBas));
        } else {
            BioAssayDimension longestBad = this.checkRagged(dims);
            if (longestBad == null) {
                newResults.addAll(this.unpack(vecsForBas));
            } else {
                newResults.addAll(this.unpack(vecsForBas, longestBad));
            }
        }
    }
    if (!newResults.isEmpty()) {
        this.cacheResults(newResults);
        newResults = this.sliceSubsets(ees, newResults);
        results.addAll(newResults);
    }
    return results;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet)

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