Search in sources :

Example 6 with WhatsNew

use of ubic.gemma.core.analysis.report.WhatsNew in project Gemma by PavlidisLab.

the class ExpressionExperimentController method loadCountsForDataSummaryTable.

/**
 * AJAX method to get data for database summary table, returned as a JSON object the slow part here is loading each
 * new or updated object in whatsNewService.retrieveReport() -> fetch()
 *
 * @return json
 */
public JSONObject loadCountsForDataSummaryTable() {
    JSONObject summary = new JSONObject();
    net.sf.json.JSONArray taxonEntries = new net.sf.json.JSONArray();
    long bioAssayCount = bioAssayService.countAll();
    long arrayDesignCount = arrayDesignService.countAll();
    Map<Taxon, Long> unsortedEEsPerTaxon = expressionExperimentService.getPerTaxonCount();
    /*
         * Sort taxa by name.
         */
    TreeMap<Taxon, Long> eesPerTaxon = new TreeMap<>(new Comparator<Taxon>() {

        @Override
        public int compare(Taxon o1, Taxon o2) {
            return o1.getScientificName().compareTo(o2.getScientificName());
        }
    });
    // expressionExperimentService.countAll();
    long expressionExperimentCount = 0;
    for (Taxon t : unsortedEEsPerTaxon.keySet()) {
        Long c = unsortedEEsPerTaxon.get(t);
        eesPerTaxon.put(t, c);
        expressionExperimentCount += c;
    }
    // this is the slow part
    WhatsNew wn = whatsNewService.retrieveReport();
    if (wn == null) {
        wn = whatsNewService.getReport();
    }
    if (wn != null) {
        // Get count for new assays
        int newAssayCount = wn.getNewAssayCount();
        Collection<ExpressionExperiment> newExpressionExperiments = wn.getNewExpressionExperiments();
        Collection<Long> newExpressionExperimentIds = (newExpressionExperiments != null) ? EntityUtils.getIds(newExpressionExperiments) : new ArrayList<Long>();
        Collection<ExpressionExperiment> updatedExpressionExperiments = wn.getUpdatedExpressionExperiments();
        Collection<Long> updatedExpressionExperimentIds = (updatedExpressionExperiments != null) ? EntityUtils.getIds(updatedExpressionExperiments) : new ArrayList<Long>();
        int newExpressionExperimentCount = (newExpressionExperiments != null) ? newExpressionExperiments.size() : 0;
        int updatedExpressionExperimentCount = (updatedExpressionExperiments != null) ? updatedExpressionExperiments.size() : 0;
        /* Store counts for new and updated experiments by taxonId */
        Map<Taxon, Collection<Long>> newEEsPerTaxon = wn.getNewEEIdsPerTaxon();
        Map<Taxon, Collection<Long>> updatedEEsPerTaxon = wn.getUpdatedEEIdsPerTaxon();
        for (Taxon t : unsortedEEsPerTaxon.keySet()) {
            JSONObject taxLine = new JSONObject();
            taxLine.put("taxonId", t.getId());
            taxLine.put("taxonName", t.getScientificName());
            taxLine.put("totalCount", eesPerTaxon.get(t));
            if (newEEsPerTaxon.containsKey(t)) {
                taxLine.put("newCount", newEEsPerTaxon.get(t).size());
                taxLine.put("newIds", newEEsPerTaxon.get(t));
            }
            if (updatedEEsPerTaxon.containsKey(t)) {
                taxLine.put("updatedCount", updatedEEsPerTaxon.get(t).size());
                taxLine.put("updatedIds", updatedEEsPerTaxon.get(t));
            }
            taxonEntries.add(taxLine);
        }
        summary.element("sortedCountsPerTaxon", taxonEntries);
        // Get count for new and updated array designs
        Collection<ArrayDesign> newArrayDesigns = wn.getNewArrayDesigns();
        int newArrayCount = (newArrayDesigns != null) ? newArrayDesigns.size() : 0;
        Collection<ArrayDesign> updatedArrayDesigns = wn.getUpdatedArrayDesigns();
        int updatedArrayCount = (updatedArrayDesigns != null) ? updatedArrayDesigns.size() : 0;
        boolean drawNewColumn = (newExpressionExperimentCount > 0 || newArrayCount > 0 || newAssayCount > 0);
        boolean drawUpdatedColumn = (updatedExpressionExperimentCount > 0 || updatedArrayCount > 0);
        String date = (wn.getDate() != null) ? DateFormat.getDateInstance(DateFormat.LONG).format(wn.getDate()) : "";
        date = date.replace('-', ' ');
        summary.element("updateDate", date);
        summary.element("drawNewColumn", drawNewColumn);
        summary.element("drawUpdatedColumn", drawUpdatedColumn);
        if (newAssayCount != 0)
            summary.element("newBioAssayCount", new Long(newAssayCount));
        if (newArrayCount != 0)
            summary.element("newArrayDesignCount", new Long(newArrayCount));
        if (updatedArrayCount != 0)
            summary.element("updatedArrayDesignCount", new Long(updatedArrayCount));
        if (newExpressionExperimentCount != 0)
            summary.element("newExpressionExperimentCount", newExpressionExperimentCount);
        if (updatedExpressionExperimentCount != 0)
            summary.element("updatedExpressionExperimentCount", updatedExpressionExperimentCount);
        if (newExpressionExperimentCount != 0)
            summary.element("newExpressionExperimentIds", newExpressionExperimentIds);
        if (updatedExpressionExperimentCount != 0)
            summary.element("updatedExpressionExperimentIds", updatedExpressionExperimentIds);
    }
    summary.element("bioAssayCount", bioAssayCount);
    summary.element("arrayDesignCount", arrayDesignCount);
    summary.element("expressionExperimentCount", expressionExperimentCount);
    return summary;
}
Also used : ArrayDesign(ubic.gemma.model.expression.arrayDesign.ArrayDesign) Taxon(ubic.gemma.model.genome.Taxon) JSONObject(net.sf.json.JSONObject) WhatsNew(ubic.gemma.core.analysis.report.WhatsNew)

Aggregations

WhatsNew (ubic.gemma.core.analysis.report.WhatsNew)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 ModelAndView (org.springframework.web.servlet.ModelAndView)3 Calendar (java.util.Calendar)2 Date (java.util.Date)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 Taxon (ubic.gemma.model.genome.Taxon)2 HashMap (java.util.HashMap)1 JSONObject (net.sf.json.JSONObject)1 Before (org.junit.Before)1 ArrayDesign (ubic.gemma.model.expression.arrayDesign.ArrayDesign)1