Search in sources :

Example 1 with GeoConverter

use of ubic.gemma.core.loader.expression.geo.GeoConverter 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 2 with GeoConverter

use of ubic.gemma.core.loader.expression.geo.GeoConverter 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;
}
Also used : DatabaseEntry(ubic.gemma.model.common.description.DatabaseEntry) ArrayDesignsForExperimentCache(ubic.gemma.persistence.util.ArrayDesignsForExperimentCache) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GeoDomainObjectGenerator(ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator) GeoConverter(ubic.gemma.core.loader.expression.geo.GeoConverter)

Aggregations

GeoConverter (ubic.gemma.core.loader.expression.geo.GeoConverter)2 GeoDomainObjectGenerator (ubic.gemma.core.loader.expression.geo.GeoDomainObjectGenerator)2 DatabaseEntry (ubic.gemma.model.common.description.DatabaseEntry)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1 CompositeSequence (ubic.gemma.model.expression.designElement.CompositeSequence)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 ArrayDesignsForExperimentCache (ubic.gemma.persistence.util.ArrayDesignsForExperimentCache)1