{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Compute Sepal score\n", "\n", "This example shows how to compute the Sepal score for spatially variable genes identification.\n", "\n", "The Sepal score is a method that simulates a diffusion process to quantify spatial structure in tissue.\n", "See {cite}`andersson2021` for reference.\n", "\n", ":::{seealso}\n", "\n", " - See {doc}`compute_co_occurrence` and\n", " {doc}`compute_moran` for other scores to identify spatially variable genes.\n", " - See {doc}`compute_spatial_neighbors` for general usage of\n", " {func}`squidpy.gr.spatial_neighbors`.\n", "\n", ":::\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "AnnData object with n_obs × n_vars = 2688 × 18078\n", " obs: 'in_tissue', 'array_row', 'array_col', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'pct_counts_in_top_50_genes', 'pct_counts_in_top_100_genes', 'pct_counts_in_top_200_genes', 'pct_counts_in_top_500_genes', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'n_counts', 'leiden', 'cluster'\n", " var: 'gene_ids', 'feature_types', 'genome', 'mt', 'n_cells_by_counts', 'mean_counts', 'log1p_mean_counts', 'pct_dropout_by_counts', 'total_counts', 'log1p_total_counts', 'n_cells', 'highly_variable', 'highly_variable_rank', 'means', 'variances', 'variances_norm'\n", " uns: 'cluster_colors', 'hvg', 'leiden', 'leiden_colors', 'neighbors', 'pca', 'rank_genes_groups', 'spatial', 'umap'\n", " obsm: 'X_pca', 'X_umap', 'spatial'\n", " varm: 'PCs'\n", " obsp: 'connectivities', 'distances'" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import squidpy as sq\n", "\n", "adata = sq.datasets.visium_hne_adata()\n", "adata" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "We can compute the Sepal score with {func}`squidpy.gr.sepal`.\n", "there are 2 important aspects to consider when computing sepal:\n", "\n", "- The function only accepts grid-like spatial graphs. Make sure to specify the\n", " maximum number of neighbors in your data (6 for an hexagonal grid like Visium)\n", " with ``max_neighs = 6``.\n", "- It is useful to filter out genes that are expressed in very few observations\n", " and might be wrongly identified as being spatially variable. If you are performing\n", " pre-processing with Scanpy, there is a convenient function that can be used BEFORE\n", " normalization {func}`scanpy.pp.calculate_qc_metrics`. It computes several useful\n", " summary statistics on both observation and feature axis. We will be using the\n", " ``n_cells`` columns in {attr}`anndata.AnnData.var` to filter out genes that are expressed in\n", " less than 100 observations.\n", "\n", "Before computing the Sepal score, we first need to compute a spatial graph with {func}`squidpy.gr.spatial_neighbors`.\n", "We will also subset the number of genes to evaluate for efficiency purposes.\n", "\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { "model_id": "f04016260feb4043af6514e1e3f3f723", "version_major": 2, "version_minor": 0 }, "text/plain": [ " 0%| | 0/100 [00:00, ?/s]" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
| \n", " | sepal_score | \n", "
|---|---|
| Lct | \n", "7.868 | \n", "
| 1500015O10Rik | \n", "7.085 | \n", "
| Ecel1 | \n", "5.274 | \n", "
| Fzd5 | \n", "4.694 | \n", "
| Cfap65 | \n", "4.095 | \n", "
| C1ql2 | \n", "3.144 | \n", "
| Slc9a2 | \n", "2.947 | \n", "
| Gm17634 | \n", "2.904 | \n", "
| St18 | \n", "2.584 | \n", "
| Des | \n", "2.494 | \n", "