<jupyter_start><jupyter_text>Introduction Gene set enrichment is a common downstream task after differential expression analysis. There exist dedicated paackages and algorithms for this purpose. diffxpy provides a simple hypergeometric test to test for enrichment of differentially expressed genes versus defined annotated gene sets. The rationale for including this workflow is that the analyst can directly run these enrichment tests on diffxpy output objects to obtain a first enrichment analysis with very little effort.The annotated reference gene sets can be manually tailored or loaded from publically available files, such as those provided by MSigDB. The enrichment API of diffxpy offers a simple interface for both cases.  Generate some data:<jupyter_code>from batchglm.api.models.glm_nb import Simulator

sim = Simulator(num_observations=2000, num_features=100)
sim.generate_sample_description(num_batches=0, num_conditions=2)
sim.generate_params()
sim.generate_data()<jupyter_output><empty_output><jupyter_text>Create anndata object:<jupyter_code>adata = sc.AnnData(X=np.asarray(sim.x), obs=sim.sample_description)<jupyter_output>Transforming to str index.<jupyter_text>From here on, we can treat the anndata object as a container of the count matrix, the sample_description and the gene_names and we only pass adata to the diffxpy functions.  Create annotated reference set If you do not want to manually curate gene sets, you can also loads sets via `rs.read_from_file()`. Here, we make up two different annotated sets (`setA`, `setB`) with gene names from the data simulation:<jupyter_code>adata.var_names
rs = de.enrich.RefSets()
rs.add(id="setA", source="made_up", gene_ids=np.array(['2', '5', '22', '23']))
rs.add(id="setB", source="made_up", gene_ids=np.array(['22', '15', '16', '44', '55', '98', '99']))<jupyter_output><empty_output><jupyter_text>Run differential expression test:The t-test checks if two groups of samples differ significantly in one gene.Therefore, it has to be provided with a parameter `grouping` which specifies the group membership of each sample.It can be either the name of a column in `sample_description` or a vector of length `num_observations`.<jupyter_code>det = de.test.t_test(
    data=adata,
    grouping="condition"
)<jupyter_output><empty_output><jupyter_text>Perform enrichment<jupyter_code>enr = de.enrich.test(det=det, ref=rs, threshold=0.005, clean_ref=False)
enr.summary()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup