Search in sources :

Example 1 with JsonReaderResponse

use of ubic.gemma.web.remote.JsonReaderResponse in project Gemma by PavlidisLab.

the class CharacteristicBrowserController method browse.

public JsonReaderResponse<AnnotationValueObject> browse(ListBatchCommand batch) {
    Integer count = characteristicService.countAll();
    List<AnnotationValueObject> results = new ArrayList<>();
    Collection<Characteristic> records;
    if (StringUtils.isNotBlank(batch.getSort())) {
        String o = batch.getSort();
        String orderBy;
        switch(o) {
            case "className":
                orderBy = "category";
                break;
            case "termName":
                orderBy = "value";
                break;
            case "evidenceCode":
                orderBy = "evidenceCode";
                break;
            default:
                throw new IllegalArgumentException("Unknown sort field: " + o);
        }
        boolean descending = batch.getDir() != null && batch.getDir().equalsIgnoreCase("DESC");
        records = characteristicService.browse(batch.getStart(), batch.getLimit(), orderBy, descending);
    } else {
        records = characteristicService.browse(batch.getStart(), batch.getLimit());
    }
    Map<Characteristic, Object> charToParent = characteristicService.getParents(records);
    for (Object o : records) {
        Characteristic c = (Characteristic) o;
        Object parent = charToParent.get(c);
        AnnotationValueObject avo = new AnnotationValueObject();
        avo.setId(c.getId());
        avo.setClassName(c.getCategory());
        avo.setTermName(c.getValue());
        if (c.getEvidenceCode() != null)
            avo.setEvidenceCode(c.getEvidenceCode().toString());
        populateClassValues(c, avo);
        if (parent != null) {
            populateParentInformation(avo, parent);
        }
        results.add(avo);
    }
    return new JsonReaderResponse<>(results, count);
}
Also used : Characteristic(ubic.gemma.model.common.description.Characteristic) VocabCharacteristic(ubic.gemma.model.common.description.VocabCharacteristic) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) ArrayList(java.util.ArrayList) AnnotationValueObject(ubic.gemma.model.common.description.AnnotationValueObject) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse)

Example 2 with JsonReaderResponse

use of ubic.gemma.web.remote.JsonReaderResponse in project Gemma by PavlidisLab.

the class BibliographicReferenceControllerImpl method browse.

@Override
public JsonReaderResponse<BibliographicReferenceValueObject> browse(ListBatchCommand batch) {
    Integer count = this.bibliographicReferenceService.countAll();
    List<BibliographicReference> records = this.getBatch(batch);
    Map<BibliographicReference, Collection<ExpressionExperiment>> relatedExperiments = this.bibliographicReferenceService.getRelatedExperiments(records);
    List<BibliographicReferenceValueObject> valueObjects = new ArrayList<>();
    for (BibliographicReference ref : records) {
        ref = this.bibliographicReferenceService.thaw(ref);
        BibliographicReferenceValueObject vo = new BibliographicReferenceValueObject(ref);
        if (relatedExperiments.containsKey(ref)) {
            vo.setExperiments(expressionExperimentService.loadValueObjects(relatedExperiments.get(ref)));
        }
        valueObjects.add(vo);
        // adding phenotype information to the Bibliographic Reference
        Collection<PhenotypeAssociation> phenotypeAssociations = this.phenotypeAssociationService.findPhenotypesForBibliographicReference(vo.getPubAccession());
        Collection<BibliographicPhenotypesValueObject> bibliographicPhenotypesValueObjects = BibliographicPhenotypesValueObject.phenotypeAssociations2BibliographicPhenotypesValueObjects(phenotypeAssociations);
        vo.setBibliographicPhenotypes(bibliographicPhenotypesValueObjects);
    }
    return new JsonReaderResponse<>(valueObjects, count);
}
Also used : PhenotypeAssociation(ubic.gemma.model.association.phenotype.PhenotypeAssociation) BibliographicReferenceValueObject(ubic.gemma.model.common.description.BibliographicReferenceValueObject) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse) BibliographicReference(ubic.gemma.model.common.description.BibliographicReference) BibliographicPhenotypesValueObject(ubic.gemma.model.genome.gene.phenotype.valueObject.BibliographicPhenotypesValueObject)

Example 3 with JsonReaderResponse

use of ubic.gemma.web.remote.JsonReaderResponse in project Gemma by PavlidisLab.

the class ExpressionExperimentController method loadExpressionExperimentsWithQcIssues.

/**
 * AJAX; get a collection of experiments that have had samples removed due to outliers
 * TODO: and experiment that have possible batch effects detected
 *
 * @return json reader response
 */
public JsonReaderResponse<JSONObject> loadExpressionExperimentsWithQcIssues() {
    Collection<ExpressionExperiment> outlierEEs = expressionExperimentService.getExperimentsWithOutliers();
    Collection<ExpressionExperiment> ees = new HashSet<>();
    ees.addAll(outlierEEs);
    // ees.addAll( batchEffectEEs );
    List<JSONObject> jsonRecords = new ArrayList<>();
    for (ExpressionExperiment ee : ees) {
        // noinspection MismatchedQueryAndUpdateOfCollection
        JSONObject record = new JSONObject();
        record.element("id", ee.getId());
        record.element("shortName", ee.getShortName());
        record.element("name", ee.getName());
        if (outlierEEs.contains(ee)) {
            record.element("sampleRemoved", true);
        }
        // record.element( "batchEffect", batchEffectEEs.contains( ee ) );
        jsonRecords.add(record);
    }
    return new JsonReaderResponse<>(jsonRecords);
}
Also used : JSONObject(net.sf.json.JSONObject) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse)

Example 4 with JsonReaderResponse

use of ubic.gemma.web.remote.JsonReaderResponse in project Gemma by PavlidisLab.

the class GeneralSearchControllerImpl method ajaxSearch.

@Override
public JsonReaderResponse<SearchResult> ajaxSearch(SearchSettingsValueObject settingsValueObject) {
    SearchSettings settings = SearchSettingsValueObject.toEntity(settingsValueObject);
    List<SearchResult> finalResults = new ArrayList<>();
    if (settings == null || StringUtils.isBlank(settings.getQuery()) || StringUtils.isBlank(settings.getQuery().replaceAll("\\*", ""))) {
        // FIXME validate input better, and return error.
        BaseFormController.log.info("No query or invalid.");
        // return new ListRange( finalResults );
        throw new IllegalArgumentException("Query '" + settings + "' was invalid");
    }
    StopWatch watch = new StopWatch();
    watch.start();
    ((SearchSettingsImpl) settings).setDoHighlighting(true);
    Map<Class<?>, List<SearchResult>> searchResults = searchService.search(settings);
    watch.stop();
    if (watch.getTime() > 500) {
        BaseFormController.log.info("Search service work on: " + settings + " took " + watch.getTime() + " ms");
    }
    /*
         * FIXME sort by the number of hits per class, so smallest number of hits is at the top.
         */
    watch.reset();
    watch.start();
    if (searchResults != null) {
        for (Class<?> clazz : searchResults.keySet()) {
            List<SearchResult> results = searchResults.get(clazz);
            if (results.size() == 0)
                continue;
            BaseFormController.log.info("Search for: " + settings + "; result: " + results.size() + " " + clazz.getSimpleName() + "s");
            /*
                 * Now put the valueObjects inside the SearchResults in score order.
                 */
            Collections.sort(results);
            this.fillValueObjects(clazz, results, settings);
            finalResults.addAll(results);
        }
    }
    if (watch.getTime() > 500) {
        BaseFormController.log.info("Final unpacking of results for query:" + settings + " took " + watch.getTime() + " ms");
    }
    return new JsonReaderResponse<>(finalResults);
}
Also used : SearchSettingsImpl(ubic.gemma.model.common.search.SearchSettingsImpl) SearchSettings(ubic.gemma.model.common.search.SearchSettings) SearchResult(ubic.gemma.core.search.SearchResult) JsonReaderResponse(ubic.gemma.web.remote.JsonReaderResponse) StopWatch(org.apache.commons.lang3.time.StopWatch)

Aggregations

JsonReaderResponse (ubic.gemma.web.remote.JsonReaderResponse)4 ArrayList (java.util.ArrayList)1 JSONObject (net.sf.json.JSONObject)1 StopWatch (org.apache.commons.lang3.time.StopWatch)1 SearchResult (ubic.gemma.core.search.SearchResult)1 PhenotypeAssociation (ubic.gemma.model.association.phenotype.PhenotypeAssociation)1 AnnotationValueObject (ubic.gemma.model.common.description.AnnotationValueObject)1 BibliographicReference (ubic.gemma.model.common.description.BibliographicReference)1 BibliographicReferenceValueObject (ubic.gemma.model.common.description.BibliographicReferenceValueObject)1 Characteristic (ubic.gemma.model.common.description.Characteristic)1 VocabCharacteristic (ubic.gemma.model.common.description.VocabCharacteristic)1 SearchSettings (ubic.gemma.model.common.search.SearchSettings)1 SearchSettingsImpl (ubic.gemma.model.common.search.SearchSettingsImpl)1 BibliographicPhenotypesValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.BibliographicPhenotypesValueObject)1