{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Extract summary features\n", "========================\n", "\n", "This example shows how to extract summary features from the tissue\n", "image.\n", "\n", "Summary features give a good overview over the intensity of each image\n", "channels at the location of the Visium spots. They are calculated by\n", "using `features = 'summary'`, which calls\n", "{func}`squidpy.im.ImageContainer.features_summary`.\n", "\n", "In addition to `feature_name` and `channels` we can specify the\n", "following `features_kwargs`:\n", "\n", "> - `quantiles` - quantiles that are computed. By default, the 0.9th,\n", "> 0.5th, and 0.1th quantiles are calculated.\n", "\n", ":::{seealso}\n", "\n", " See {doc}`compute_features` for general usage\n", " of {func}`squidpy.im.calculate_image_features`.\n", " \n", ":::\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import squidpy as sq" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "First, let\\'s load the fluorescence Visium dataset.\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# get spatial dataset including hires tissue image\n", "img = sq.datasets.visium_fluo_image_crop()\n", "adata = sq.datasets.visium_fluo_adata_crop()" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "Then, we calculate the 0.1th quantile, mean and standard deviation for\n", "the Visium spots of the fluorescence channels 0 (DAPI) and 1 (GFAP). In\n", "order to get statistics of only the tissue underneath the spots, we use\n", "the argument `mask_circle = True`. When not setting this flag,\n", "statistics are calculated using a square crop centered on the spot.\n" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [], "source": [ "# calculate summary features and save in key \"summary_features\"\n", "sq.im.calculate_image_features(\n", " adata,\n", " img,\n", " features=\"summary\",\n", " features_kwargs={\n", " \"summary\": {\n", " \"quantiles\": [0.1],\n", " \"channels\": [0, 1],\n", " }\n", " },\n", " key_added=\"summary_features\",\n", " mask_circle=True,\n", " show_progress_bar=False,\n", ")" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "The result is stored in {attr}`anndata.AnnData.obsm`\\ `['summary_features']`.\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
| \n", " | summary_ch-0_quantile-0.1 | \n", "summary_ch-0_mean | \n", "summary_ch-0_std | \n", "summary_ch-1_quantile-0.1 | \n", "summary_ch-1_mean | \n", "summary_ch-1_std | \n", "
|---|---|---|---|---|---|---|
| AAACGAGACGGTTGAT-1 | \n", "0.0 | \n", "6849.760120 | \n", "14383.136990 | \n", "0.0 | \n", "3762.582691 | \n", "2462.922155 | \n", "
| AAAGGGATGTAGCAAG-1 | \n", "0.0 | \n", "4469.448519 | \n", "11304.932832 | \n", "0.0 | \n", "3824.862145 | \n", "2153.804234 | \n", "
| AAATGGCATGTCTTGT-1 | \n", "0.0 | \n", "5944.567897 | \n", "9808.327041 | \n", "0.0 | \n", "5481.824787 | \n", "6747.728831 | \n", "
| AAATGGTCAATGTGCC-1 | \n", "0.0 | \n", "5259.799257 | \n", "9115.113451 | \n", "0.0 | \n", "2628.194501 | \n", "1418.504292 | \n", "
| AAATTAACGGGTAGCT-1 | \n", "0.0 | \n", "4468.428701 | \n", "10285.605481 | \n", "0.0 | \n", "4036.154302 | \n", "4447.304626 | \n", "