{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Example Workflow with spatialproteomics\n", "Welcome to spatialproteomics! In this notebook, we will go through an example workflow by looking at the following steps:\n", "1. Reading in a highly multiplexed image and creating a spatialproteomics object\n", "2. Performing basic image processing steps to boost the signal-to-noise ratio\n", "3. Performing cell segmentation using _cellpose_\n", "4. Quantifying protein expression per cell\n", "5. Predicting cell types with a simple argmax technique\n", "6. Plotting the results" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "%load_ext autoreload\n", "%autoreload 2\n", "\n", "import spatialproteomics as sp\n", "from skimage.io import imread\n", "import matplotlib.pyplot as plt\n", "from scipy.signal import medfilt2d\n", "import pandas as pd" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1. Getting Started\n", "\n", "Before we can get started with _spatialproteomics_, we first need to read in the image. This can be done with the _skimage_ or _tifffile_ libraries." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "(5, 500, 500)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# reading in the image and displaying its shape\n", "image = imread('../../data/input.tiff')\n", "image.shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can see that our image has 5 channels and has a size of 500 by 500 pixels. Next, we want to create a _spatialproteomics_ object and store the image within the object. To do this, we also need to feed in the names of the channels." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [], "source": [ "sp_object = sp.load_image_data(image, channel_coords=['DAPI', 'CD4', 'CD8', 'FOXP3', 'BCL6'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Instead of manually typing out all channels in the form of a list, you can also simply read it in from a file, and then provide the resulting list to spatialproteomics." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/plain": [ "['DAPI', 'CD4', 'CD8', 'FOXP3', 'BCL6']" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "markers = pd.read_csv('../../data/markerlist.txt', header=None)[0].tolist()\n", "markers" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "tags": [] }, "outputs": [], "source": [ "# loading the markers into the object\n", "sp_object = sp.load_image_data(image, channel_coords=markers)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`sp.load_image_data()` returns an xarray object that we can simply inspect by calling in an jupyter cell. Note that the image is stored as the data variable `_image`." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset>\n", "Dimensions: (channels: 5, y: 500, x: 500)\n", "Coordinates:\n", " * channels (channels) <U5 'DAPI' 'CD4' 'CD8' 'FOXP3' 'BCL6'\n", " * y (y) int64 0 1 2 3 4 5 6 7 8 ... 492 493 494 495 496 497 498 499\n", " * x (x) int64 0 1 2 3 4 5 6 7 8 ... 492 493 494 495 496 497 498 499\n", "Data variables:\n", " _image (channels, y, x) uint16 10816 12359 14504 10965 ... 147 129 149 59