Search in sources :

Example 1 with CoexpressionMetaValueObject

use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject in project Gemma by PavlidisLab.

the class CoexpressionSearchController method doSearchQuickComplete.

/**
 * Do a search that fills in the edges among the genes already found. Maps to doSearchQuickComplete in javascript.
 *
 * @param searchOptions search options
 * @param queryGeneIds  the genes which were used originally to start the search
 * @return coexp meta VO
 */
public CoexpressionMetaValueObject doSearchQuickComplete(CoexpressionSearchCommand searchOptions, Collection<Long> queryGeneIds) {
    if (searchOptions == null) {
        throw new IllegalArgumentException("Search options cannot be null");
    }
    assert queryGeneIds != null && !queryGeneIds.isEmpty();
    CoexpressionMetaValueObject result = new CoexpressionMetaValueObject();
    if (queryGeneIds.size() == 1) {
        // there is nothing to do; really we shouldn't be here.
        assert !searchOptions.getGeneIds().isEmpty();
        return this.doSearch(searchOptions);
    }
    assert searchOptions.getQueryGenesOnly();
    // Add the user's datasets to the selected datasets
    Collection<ExpressionExperiment> myEE = null;
    if (searchOptions.isUseMyDatasets()) {
        myEE = expressionExperimentService.loadAll();
    }
    Collection<Long> eeIds = this.chooseExperimentsToQuery(searchOptions, result);
    if (StringUtils.isNotBlank(result.getErrorState()))
        return result;
    if (myEE != null && !myEE.isEmpty()) {
        eeIds.addAll(EntityUtils.getIds(myEE));
    } else {
        CoexpressionSearchController.log.debug("No user data to add");
    }
    if (eeIds.isEmpty()) {
    // search all available experiments.
    } else {
        searchOptions.setEeIds(eeIds);
    }
    StopWatch timer = new StopWatch();
    timer.start();
    CoexpressionSearchController.log.info("Coexpression search for " + searchOptions.getGeneIds().size() + " genes, stringency=" + searchOptions.getStringency() + (searchOptions.getEeIds() != null ? (" ees=" + searchOptions.getEeIds().size()) : " All ees"));
    result = geneCoexpressionService.coexpressionSearchQuick(searchOptions.getEeIds(), searchOptions.getGeneIds(), searchOptions.getStringency(), -1, /* no limit in this situation anyway */
    true);
    result.setSearchSettings(searchOptions);
    if (result.getResults() == null || result.getResults().isEmpty()) {
        result.setErrorState(CoexpressionSearchController.NOTHING_FOUND_MESSAGE);
        CoexpressionSearchController.log.info("No search results for query: " + searchOptions);
    }
    if (timer.getTime() > 2000) {
        CoexpressionSearchController.log.info("Search complete: " + result.getResults().size() + " hits");
    }
    return result;
}
Also used : CoexpressionMetaValueObject(ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) StopWatch(org.apache.commons.lang3.time.StopWatch)

Example 2 with CoexpressionMetaValueObject

use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject in project Gemma by PavlidisLab.

the class CoexpressionSearchController method doSearch.

/**
 * Important entry point - called by the CoexpressionSearchTask
 *
 * @param searchOptions search options
 * @return coexp. meta VO
 */
public CoexpressionMetaValueObject doSearch(CoexpressionSearchCommand searchOptions) {
    Collection<ExpressionExperiment> myEE = null;
    CoexpressionMetaValueObject result = new CoexpressionMetaValueObject();
    if (searchOptions.getGeneIds() == null || searchOptions.getGeneIds().isEmpty()) {
        if (searchOptions.getGeneSetId() != null) {
            searchOptions.setGeneIds(geneSetService.getGeneIdsInGroup(new GeneSetValueObject(searchOptions.getGeneSetId())));
        }
        if (searchOptions.getGeneIds().isEmpty()) {
            result.setErrorState("No genes were selected");
            return result;
        }
    }
    if (searchOptions.getGeneIds().size() > CoexpressionSearchController.MAX_GENES_FOR_QUERY_GENES_ONLY_QUERY) {
        result.setErrorState("Too many genes selected, please limit searches to " + CoexpressionSearchController.MAX_GENES_FOR_QUERY_GENES_ONLY_QUERY + " genes");
        return result;
    }
    if (searchOptions.getGeneIds().size() == 0) {
        result.setErrorState("Invalid gene id(s) - no genes found");
        return result;
    }
    // Add the user's datasets to the selected datasets
    if (searchOptions.isUseMyDatasets()) {
        myEE = expressionExperimentService.loadAll();
    }
    Collection<Long> eeIds = this.chooseExperimentsToQuery(searchOptions, result);
    if (StringUtils.isNotBlank(result.getErrorState()))
        return result;
    if (myEE != null && !myEE.isEmpty()) {
        eeIds.addAll(EntityUtils.getIds(myEE));
    } else {
        CoexpressionSearchController.log.info("No user data to add");
    }
    if (eeIds.isEmpty()) {
    // search all available experiments.
    } else {
        searchOptions.setEeIds(eeIds);
    }
    CoexpressionSearchController.log.info("Starting coexpression search: " + searchOptions);
    result = geneCoexpressionService.coexpressionSearch(searchOptions.getEeIds(), searchOptions.getGeneIds(), searchOptions.getStringency(), CoexpressionSearchController.MAX_RESULTS_PER_GENE, searchOptions.getQueryGenesOnly());
    // make sure to create an empty list instead of null for front-end
    if (result.getResults() == null) {
        List<CoexpressionValueObjectExt> res = new ArrayList<>();
        result.setResults(res);
    }
    if (result.getResults().isEmpty()) {
        result.setErrorState(CoexpressionSearchController.NOTHING_FOUND_MESSAGE);
        CoexpressionSearchController.log.info("No search results for query: " + searchOptions);
    }
    return result;
}
Also used : CoexpressionMetaValueObject(ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject) CoexpressionValueObjectExt(ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt) ArrayList(java.util.ArrayList) ExpressionExperiment(ubic.gemma.model.expression.experiment.ExpressionExperiment) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject)

Example 3 with CoexpressionMetaValueObject

use of ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject in project Gemma by PavlidisLab.

the class GeneCoexpressionSearchEndpoint method invokeInternal.

/**
 * Reads the given <code>requestElement</code>, and sends a the response back.
 *
 * @param requestElement the contents of the SOAP message as DOM elements
 * @param document       a DOM document to be used for constructing <code>Node</code>s
 * @return the response element
 */
@Override
protected Element invokeInternal(Element requestElement, Document document) {
    try {
        StopWatch watch = new StopWatch();
        watch.start();
        setLocalName(LOCAL_NAME);
        String queryGeneId = getNodeValue(requestElement, "query_gene_id");
        String pairQueryGeneId = getOptionalNodeValue(requestElement, "pair_query_gene_id");
        String stringency = getNodeValue(requestElement, "stringency");
        Collection<Gene> queryGenes = new LinkedList<>();
        Gene queryGene = geneService.findByNCBIId(Integer.parseInt(queryGeneId));
        if (queryGene == null) {
            String msg = "Query gene with id [" + queryGeneId + "] cannot be found.";
            return buildBadResponse(document, msg);
        }
        queryGenes.add(queryGene);
        if (pairQueryGeneId != null) {
            Gene queryGene2 = geneService.findByNCBIId(Integer.parseInt(pairQueryGeneId));
            if (queryGene2 == null) {
                String msg = "Query gene with id [" + pairQueryGeneId + "] cannot be found.";
                return buildBadResponse(document, msg);
            }
            queryGenes.add(queryGene2);
        }
        Collection<ExpressionExperimentSet> eeSets = expressionExperimentSetService.findByName("All mouse");
        // .load(5662l); // uses 'All mouse' by default.
        ExpressionExperimentSet eeSet = eeSets.iterator().next();
        Collection<BioAssaySet> experiments = eeSet.getExperiments();
        Collection<Long> inputEeIds = new ArrayList<>();
        for (BioAssaySet e : experiments) {
            inputEeIds.add(e.getId());
        }
        CoexpressionMetaValueObject metaVO;
        if (pairQueryGeneId == null) {
            metaVO = geneCoexpressionSearchService.coexpressionSearch(inputEeIds, EntityUtils.getIds(queryGenes), Integer.valueOf(stringency), MAX_RESULTS, false);
        } else {
            metaVO = geneCoexpressionSearchService.coexpressionSearch(inputEeIds, EntityUtils.getIds(queryGenes), Integer.valueOf(stringency), MAX_RESULTS, true);
        }
        Collection<CoexpressionValueObjectExt> coexpressedGenes = metaVO.getResults();
        if (coexpressedGenes.isEmpty()) {
            String msg = "No coexpressed genes found.";
            return buildBadResponse(document, msg);
        }
        Element responseWrapper = document.createElementNS(NAMESPACE_URI, LOCAL_NAME);
        Element responseElement = document.createElementNS(NAMESPACE_URI, LOCAL_NAME + RESPONSE);
        responseWrapper.appendChild(responseElement);
        for (CoexpressionValueObjectExt cvo : coexpressedGenes) {
            Element item = document.createElement("CoexpressionSearchResult");
            Element foundGeneElement = document.createElement("found_gene_id");
            foundGeneElement.appendChild(document.createTextNode(cvo.getFoundGene().getNcbiId() == null ? "" : cvo.getFoundGene().getNcbiId().toString()));
            item.appendChild(foundGeneElement);
            Element numExperimentsElement = document.createElement("num_experiments_tested");
            numExperimentsElement.appendChild(document.createTextNode(cvo.getNumTestedIn().toString()));
            item.appendChild(numExperimentsElement);
            Element numCoexpressedElement = document.createElement("num_experiments_coexpressed");
            numCoexpressedElement.appendChild(document.createTextNode(String.valueOf(cvo.getSupportingExperiments().size())));
            item.appendChild(numCoexpressedElement);
            Element gemmaURL = document.createElement("gemma_details_url");
            gemmaURL.appendChild(document.createTextNode(Settings.getBaseUrl() + "searchCoexpression.html?g=" + queryGene.getId() + "," + cvo.getFoundGene().getId() + "&s=" + stringency + "&t=2&q&a=5662&an=All%20mouse"));
            item.appendChild(gemmaURL);
            responseElement.appendChild(item);
        }
        watch.stop();
        Long time = watch.getTime();
        if (time > 1000) {
            log.info("XML response for " + coexpressedGenes.size() + " results built in " + time + "ms.");
        }
        return responseWrapper;
    } catch (Exception e) {
        return buildBadResponse(document, e.getMessage());
    }
}
Also used : Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) StopWatch(org.apache.commons.lang3.time.StopWatch) CoexpressionMetaValueObject(ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject) Gene(ubic.gemma.model.genome.Gene) BioAssaySet(ubic.gemma.model.expression.experiment.BioAssaySet) ExpressionExperimentSet(ubic.gemma.model.analysis.expression.ExpressionExperimentSet) CoexpressionValueObjectExt(ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt)

Aggregations

CoexpressionMetaValueObject (ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject)3 ArrayList (java.util.ArrayList)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 CoexpressionValueObjectExt (ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt)2 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)2 LinkedList (java.util.LinkedList)1 Element (org.w3c.dom.Element)1 ExpressionExperimentSet (ubic.gemma.model.analysis.expression.ExpressionExperimentSet)1 BioAssaySet (ubic.gemma.model.expression.experiment.BioAssaySet)1 Gene (ubic.gemma.model.genome.Gene)1 GeneSetValueObject (ubic.gemma.model.genome.gene.GeneSetValueObject)1