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;
}
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);
}
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;
}
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);
}
}
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;
}
Aggregations