Search in sources :

Example 6 with ExpressionExperimentService

use of ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService in project Gemma by PavlidisLab.

the class ExperimentalDesignViewCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception err = processCommandLine(args);
    if (err != null)
        return err;
    ExperimentalDesignService eds = getBean(ExperimentalDesignService.class);
    ExpressionExperimentService ees = getBean(ExpressionExperimentService.class);
    Collection<ExpressionExperimentValueObject> experiments = ees.loadValueObjects(EntityUtils.getIds(ees.loadAll()), false);
    Map<Long, ExpressionExperimentValueObject> ed2ee = new HashMap<>();
    for (ExpressionExperimentValueObject expressionExperiment : experiments) {
        ed2ee.put(expressionExperiment.getExperimentalDesign(), expressionExperiment);
    }
    Collection<ExperimentalDesign> designs = eds.loadAll();
    Map<Long, Long> factor2Design = new HashMap<>();
    Map<String, Map<String, Collection<FactorValueValueObject>>> categoryMap = new TreeMap<>();
    for (ExperimentalDesign experimentalDesign : designs) {
        if (!ed2ee.containsKey(experimentalDesign.getId()))
            continue;
        for (ExperimentalFactor factor : experimentalDesign.getExperimentalFactors()) {
            factor2Design.put(factor.getId(), experimentalDesign.getId());
            String category;
            if (factor.getCategory() != null)
                category = factor.getCategory().getValue();
            else
                category = " ** NO CATEGORY ** ";
            if (!categoryMap.containsKey(category)) {
                categoryMap.put(category, new TreeMap<String, Collection<FactorValueValueObject>>());
            }
            for (FactorValue f : factor.getFactorValues()) {
                // don't list individual quantitative values.
                if (f.getMeasurement() != null)
                    continue;
                if (f.getCharacteristics().size() > 0) {
                    for (Characteristic c : f.getCharacteristics()) {
                        if (c.getCategory().equals(category)) {
                            String value = c.getValue();
                            if (value == null)
                                continue;
                            if (!categoryMap.get(category).containsKey(value)) {
                                categoryMap.get(category).put(value, new HashSet<FactorValueValueObject>());
                            }
                            categoryMap.get(category).get(value).add(new FactorValueValueObject(f, c));
                        }
                    }
                } else if (f.getValue() != null) {
                    if (!categoryMap.get(category).containsKey(f.getValue())) {
                        categoryMap.get(category).put(f.getValue(), new HashSet<FactorValueValueObject>());
                    }
                    categoryMap.get(category).get(f.getValue()).add(new FactorValueValueObject(f));
                }
            }
        }
    }
    for (String category : categoryMap.keySet()) {
        log.info("Category: " + category);
        if (category.equals("Time") || category.equals("SamplingTimePoint") || category.equals("Age")) {
            log.info(" *****  Details not shown for this category");
        }
        for (String value : categoryMap.get(category).keySet()) {
            log.info("     Value: " + value);
            for (FactorValueValueObject fv : categoryMap.get(category).get(value)) {
                // don't list individual values.
                if (fv.isMeasurement())
                    continue;
                Long factor = fv.getFactorId();
                ExpressionExperimentValueObject expressionExperimentValueObject = ed2ee.get(factor2Design.get(factor));
                if (expressionExperimentValueObject == null) {
                    log.warn("       NO EE for Factor=" + factor);
                    continue;
                }
                String ee = expressionExperimentValueObject.getShortName();
                String uri = StringUtils.isBlank(fv.getValueUri()) ? "" : " [" + fv.getValueUri() + "]";
                log.info("           " + fv.getValue() + uri + " EE=" + ee);
            }
        }
    }
    return null;
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) ExperimentalDesignService(ubic.gemma.persistence.service.expression.experiment.ExperimentalDesignService) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService)

Example 7 with ExpressionExperimentService

use of ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService in project Gemma by PavlidisLab.

the class ExpressionExperimentServiceTest method testGetByTaxon.

@Test
public void testGetByTaxon() {
    ExpressionExperimentService eeService = this.getBean(ExpressionExperimentService.class);
    Taxon taxon = taxonService.findByCommonName("mouse");
    Collection<ExpressionExperiment> list = expressionExperimentService.findByTaxon(taxon);
    assertNotNull(list);
    Taxon checkTaxon = eeService.getTaxon(list.iterator().next());
    assertEquals(taxon, checkTaxon);
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) Test(org.junit.Test) BaseSpringContextTest(ubic.gemma.core.testing.BaseSpringContextTest)

Example 8 with ExpressionExperimentService

use of ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService in project Gemma by PavlidisLab.

the class AbstractSpringAwareCLI method noNeedToRun.

/**
 * @param auditable  auditable
 * @param eventClass can be null
 * @return boolean
 */
protected boolean noNeedToRun(Auditable auditable, Class<? extends AuditEventType> eventClass) {
    boolean needToRun = true;
    Date skipIfLastRunLaterThan = this.getLimitingDate();
    List<AuditEvent> events = this.auditEventService.getEvents(auditable);
    // assume okay unless indicated otherwise
    boolean okToRun = true;
    // count.
    for (int j = events.size() - 1; j >= 0; j--) {
        AuditEvent event = events.get(j);
        if (event == null) {
            // legacy of ordered-list which could end up with gaps; should not be needed any more
            continue;
        }
        AuditEventType eventType = event.getEventType();
        if (eventType != null && eventClass != null && eventClass.isAssignableFrom(eventType.getClass()) && !eventType.getClass().getSimpleName().startsWith("Fail")) {
            if (skipIfLastRunLaterThan != null) {
                if (event.getDate().after(skipIfLastRunLaterThan)) {
                    AbstractCLI.log.info(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
                    errorObjects.add(auditable + ": " + " run more recently than " + skipIfLastRunLaterThan);
                    needToRun = false;
                }
            } else {
                // it has been run already at some point
                needToRun = false;
            }
        }
    }
    /*
         * Always skip if the object is curatable and troubled
         */
    if (auditable instanceof Curatable) {
        Curatable curatable = (Curatable) auditable;
        // not ok if troubled
        okToRun = !curatable.getCurationDetails().getTroubled();
        // special case for expression experiments - check associated ADs.
        if (okToRun && curatable instanceof ExpressionExperiment) {
            ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
            for (ArrayDesign ad : ees.getArrayDesignsUsed((ExpressionExperiment) auditable)) {
                if (ad.getCurationDetails().getTroubled()) {
                    // not ok if even one parent AD is troubled, no need to check the remaining ones.
                    okToRun = false;
                    break;
                }
            }
        }
        if (!okToRun) {
            AbstractCLI.log.info(auditable + ": has an active 'trouble' flag");
            errorObjects.add(auditable + ": has an active 'trouble' flag");
        }
    }
    return !needToRun || !okToRun;
}
Also used : Curatable(ubic.gemma.model.common.auditAndSecurity.curation.Curatable) AuditEventType(ubic.gemma.model.common.auditAndSecurity.eventType.AuditEventType) ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) AuditEvent(ubic.gemma.model.common.auditAndSecurity.AuditEvent) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) Date(java.util.Date)

Example 9 with ExpressionExperimentService

use of ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService in project Gemma by PavlidisLab.

the class GeoBrowserServiceParseTest method testParse3.

@Test
public void testParse3() throws Exception {
    try (InputStream is = this.getClass().getResourceAsStream("/data/loader/expression/geo/geo.esummary.test2.xml");
        BufferedReader r = new BufferedReader(new InputStreamReader(is))) {
        String l;
        StringBuilder buf = new StringBuilder();
        while ((l = r.readLine()) != null) {
            buf.append(l);
        }
        String response = buf.toString();
        GeoBrowserServiceImpl serv = new GeoBrowserServiceImpl();
        serv.afterPropertiesSet();
        ArrayDesignService ads = createMock(ArrayDesignService.class);
        ExpressionExperimentService ees = createMock(ExpressionExperimentService.class);
        serv.arrayDesignService = ads;
        serv.expressionExperimentService = ees;
        expect(ads.findByShortName("GPL3829")).andReturn(null);
        expect(ees.findByShortName("GSE21230")).andReturn(null);
        replay(ads);
        serv.formatDetails(response);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) ArrayDesignService(ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService) Test(org.junit.Test)

Example 10 with ExpressionExperimentService

use of ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService in project Gemma by PavlidisLab.

the class GeoGrabberCli method doWork.

@Override
protected Exception doWork(String[] args) {
    Exception e = super.processCommandLine(args);
    if (e != null)
        return e;
    Set<String> seen = new HashSet<>();
    GeoBrowserService gbs = this.getBean(GeoBrowserService.class);
    ExpressionExperimentService ees = this.getBean(ExpressionExperimentService.class);
    try {
        int start = 0;
        int numfails = 0;
        int chunksize = 100;
        while (true) {
            List<GeoRecord> recs = gbs.getRecentGeoRecords(start, chunksize);
            if (recs.isEmpty()) {
                AbstractCLI.log.info("No records received for start=" + start);
                numfails++;
                if (numfails > 10) {
                    AbstractCLI.log.info("Giving up");
                    break;
                }
                try {
                    Thread.sleep(500);
                } catch (InterruptedException ignored) {
                }
                start++;
                continue;
            }
            start++;
            for (GeoRecord geoRecord : recs) {
                if (seen.contains(geoRecord.getGeoAccession())) {
                    continue;
                }
                if (ees.findByShortName(geoRecord.getGeoAccession()) != null) {
                    continue;
                }
                if (!ees.findByAccession(geoRecord.getGeoAccession()).isEmpty()) {
                    continue;
                }
                System.out.println(geoRecord.getGeoAccession() + "\t" + geoRecord.getOrganisms().iterator().next() + "\t" + geoRecord.getNumSamples() + "\t" + geoRecord.getTitle() + "\t" + StringUtils.join(geoRecord.getCorrespondingExperiments(), ",") + "\t" + geoRecord.getSeriesType());
                seen.add(geoRecord.getGeoAccession());
            }
        }
    } catch (IOException | ParseException exception) {
        return exception;
    }
    return null;
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) ParseException(java.text.ParseException) GeoRecord(ubic.gemma.core.loader.expression.geo.model.GeoRecord) GeoBrowserService(ubic.gemma.core.loader.expression.geo.service.GeoBrowserService) ExpressionExperimentService(ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService) ParseException(java.text.ParseException) HashSet(java.util.HashSet)

Aggregations

ExpressionExperimentService (ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService)10 Test (org.junit.Test)4 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)3 ArrayDesignService (ubic.gemma.persistence.service.expression.arrayDesign.ArrayDesignService)3 BufferedReader (java.io.BufferedReader)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 InputStreamReader (java.io.InputStreamReader)2 ParseException (java.text.ParseException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashSet (java.util.HashSet)1 ExperimentalFactorOntologyService (ubic.basecode.ontology.providers.ExperimentalFactorOntologyService)1 ExpressionExperimentBibRefFinder (ubic.gemma.core.loader.entrez.pubmed.ExpressionExperimentBibRefFinder)1 PubMedXMLFetcher (ubic.gemma.core.loader.entrez.pubmed.PubMedXMLFetcher)1 GeoRecord (ubic.gemma.core.loader.expression.geo.model.GeoRecord)1 GeoBrowserService (ubic.gemma.core.loader.expression.geo.service.GeoBrowserService)1 ExperimentalDesignImporter (ubic.gemma.core.loader.expression.simple.ExperimentalDesignImporter)1 OntologyService (ubic.gemma.core.ontology.OntologyService)1 BaseSpringContextTest (ubic.gemma.core.testing.BaseSpringContextTest)1