Search in sources :

Example 6 with GeneSetValueObject

use of ubic.gemma.model.genome.gene.GeneSetValueObject 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 7 with GeneSetValueObject

use of ubic.gemma.model.genome.gene.GeneSetValueObject in project Gemma by PavlidisLab.

the class GeneSetDaoImpl method loadValueObjects.

@Override
public Collection<DatabaseBackedGeneSetValueObject> loadValueObjects(Collection<Long> ids) {
    Collection<DatabaseBackedGeneSetValueObject> result = this.loadValueObjectsLite(ids);
    for (GeneSetValueObject res : result) {
        res.setGeneIds(new HashSet<Long>());
        // noinspection unchecked
        res.getGeneIds().addAll(this.getSessionFactory().getCurrentSession().createQuery("select genes.id from GeneSet g join g.members m join m.gene genes where g.id = :id").setParameter("id", res.getId()).list());
    }
    return result;
}
Also used : DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)

Example 8 with GeneSetValueObject

use of ubic.gemma.model.genome.gene.GeneSetValueObject in project Gemma by PavlidisLab.

the class GeneSetValueObjectHelperImpl method fillSessionBoundValueObject.

private void fillSessionBoundValueObject(SessionBoundGeneSetValueObject sbgsvo, GeneSet gs) {
    sbgsvo.setName(gs.getName());
    sbgsvo.setDescription(gs.getDescription());
    // GO group gene sets don't have ids
    if (gs.getId() == null) {
        sbgsvo.setSize(gs.getMembers() != null ? gs.getMembers().size() : 0);
    } else {
        // this case may never happen as this is only called from convertToGoValueObject() leaving here in case
        // this method is ever called from somewhere else
        sbgsvo.setSize(this.geneSetService.getSize(new GeneSetValueObject(gs.getId())));
    }
    Collection<Long> gids = new HashSet<>();
    for (GeneSetMember gm : gs.getMembers()) {
        gids.add(gm.getGene().getId());
    }
    sbgsvo.setGeneIds(gids);
    Taxon tax = this.geneSetService.getTaxon(gs);
    if (tax != null) {
        while (tax.getParentTaxon() != null) {
            tax = tax.getParentTaxon();
        }
        sbgsvo.setTaxonId(tax.getId());
        sbgsvo.setTaxonName(tax.getCommonName());
    }
    sbgsvo.setId(new Long(-1));
    sbgsvo.setModified(false);
}
Also used : Taxon(ubic.gemma.model.genome.Taxon) GeneSetMember(ubic.gemma.model.genome.gene.GeneSetMember) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)

Example 9 with GeneSetValueObject

use of ubic.gemma.model.genome.gene.GeneSetValueObject in project Gemma by PavlidisLab.

the class GeneController method handleRequestInternal.

@RequestMapping("/downloadGeneList.html")
protected ModelAndView handleRequestInternal(HttpServletRequest request) {
    StopWatch watch = new StopWatch();
    watch.start();
    // might not be any
    Collection<Long> geneIds = ControllerUtils.extractIds(request.getParameter("g"));
    // might not be there
    Collection<Long> geneSetIds = ControllerUtils.extractIds(request.getParameter("gs"));
    // might not be there
    String geneSetName = request.getParameter("gsn");
    ModelAndView mav = new ModelAndView(new TextView());
    if ((geneIds == null || geneIds.isEmpty()) && (geneSetIds == null || geneSetIds.isEmpty())) {
        mav.addObject("text", "Could not find genes to match gene ids: {" + geneIds + "} or gene set ids {" + geneSetIds + "}");
        return mav;
    }
    Collection<GeneValueObject> genes = new ArrayList<>();
    if (geneIds != null) {
        for (Long id : geneIds) {
            genes.add(geneService.loadValueObjectById(id));
        }
    }
    if (geneSetIds != null) {
        for (Long id : geneSetIds) {
            genes.addAll(geneSetService.getGenesInGroup(new GeneSetValueObject(id)));
        }
    }
    mav.addObject("text", format4File(genes, geneSetName));
    watch.stop();
    Long time = watch.getTime();
    if (time > 100) {
        log.info("Retrieved and Formated" + genes.size() + " genes in : " + time + " ms.");
    }
    return mav;
}
Also used : GeneValueObject(ubic.gemma.model.genome.gene.GeneValueObject) ModelAndView(org.springframework.web.servlet.ModelAndView) TextView(ubic.gemma.web.view.TextView) StopWatch(org.apache.commons.lang3.time.StopWatch) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with GeneSetValueObject

use of ubic.gemma.model.genome.gene.GeneSetValueObject in project Gemma by PavlidisLab.

the class GeneSetValueObjectHelperImpl method convertToValueObject.

@Override
public DatabaseBackedGeneSetValueObject convertToValueObject(GeneSet gs) {
    if (gs == null)
        return null;
    DatabaseBackedGeneSetValueObject dbgsvo = convertToLightValueObject(gs);
    Collection<Long> ids = EntityUtils.getIds(this.geneSetService.getGenesInGroup(new GeneSetValueObject(gs.getId())));
    dbgsvo.getGeneIds().addAll(ids);
    dbgsvo.setSize(ids.size());
    return dbgsvo;
}
Also used : DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject) GeneSetValueObject(ubic.gemma.model.genome.gene.GeneSetValueObject) DatabaseBackedGeneSetValueObject(ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)

Aggregations

GeneSetValueObject (ubic.gemma.model.genome.gene.GeneSetValueObject)12 DatabaseBackedGeneSetValueObject (ubic.gemma.model.genome.gene.DatabaseBackedGeneSetValueObject)8 SessionBoundGeneSetValueObject (ubic.gemma.core.genome.gene.SessionBoundGeneSetValueObject)6 HashSet (java.util.HashSet)4 GeneValueObject (ubic.gemma.model.genome.gene.GeneValueObject)3 StopWatch (org.apache.commons.lang3.time.StopWatch)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ModelAndView (org.springframework.web.servlet.ModelAndView)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 CoexpressionMetaValueObject (ubic.gemma.core.analysis.expression.coexpression.CoexpressionMetaValueObject)1 CoexpressionValueObjectExt (ubic.gemma.core.analysis.expression.coexpression.CoexpressionValueObjectExt)1 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)1 ExpressionExperimentSetValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentSetValueObject)1 ExpressionExperimentValueObject (ubic.gemma.model.expression.experiment.ExpressionExperimentValueObject)1 Gene (ubic.gemma.model.genome.Gene)1 Taxon (ubic.gemma.model.genome.Taxon)1 GeneSetMember (ubic.gemma.model.genome.gene.GeneSetMember)1 CharacteristicValueObject (ubic.gemma.model.genome.gene.phenotype.valueObject.CharacteristicValueObject)1