Search in sources :

Example 1 with ExperimentalDesignService

use of ubic.gemma.persistence.service.expression.experiment.ExperimentalDesignService 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)

Aggregations

Characteristic (ubic.gemma.model.common.description.Characteristic)1 ExperimentalDesignService (ubic.gemma.persistence.service.expression.experiment.ExperimentalDesignService)1 ExpressionExperimentService (ubic.gemma.persistence.service.expression.experiment.ExpressionExperimentService)1