Analyse MIBI-TOF in Napari-SpatialData

Analyse MIBI-TOF in Napari-SpatialData#

This tutorial shows how to load and analyse the MIBI-TOF dataset with the Napari-SpatialData plugin.

Import packages and data#

There are two options to install napari-spatialdata:

(1) Install napari

(2a) Run pip install napari-spatialdata

or,

(2b) Clone this repo and run pip install -e .

%matplotlib inline
import matplotlib.pyplot as plt
from napari_spatialdata import Interactive
from spatialdata import SpatialData
import squidpy as sq
import scanpy as sc

plt.rcParams['figure.figsize'] = (20, 20)

Please download the MIBI-TOF data from https://spatialdata.scverse.org/en/stable/tutorials/notebooks/datasets/README.html and adjust the variable containing the location of the .zarr file.

Information regarding data licensing and attribution for the dataset listed above is available at: https://github.com/scverse/spatialdata-notebooks/tree/main/datasets.

We will load the dataset from the filepath and create a spatialdata.SpatialData object. We’ll use this object with the class Interactive to visualise this dataset in Napari.

FILE_PATH = “tutorial_data/mibitof_data/data.zarr” # Path to the data file. Change if your data is stored in a different location. sdata = SpatialData.read(FILE_PATH)

To make it easier to analyse our data, we will filter the SpatialData object by the coordinate system “point8”.

sdata = sdata.filter_by_coordinate_system("point8")
adata = sdata.table

The scikit-misc package could be required for highly variable genes identification.

Next, we will use the Scatter Widget offered by Napari SpatialData to visualize the UMAP coordinates.

First, we instantiate the Interactive class with our spatialdata.SpatialData object, and view it in Napari.

interactive = Interactive(sdata)
interactive.run()
plt.imshow(interactive.screenshot())
plt.axis('off')

We select the coordinate system “point8” and load the elements “point8_image” and “point8_labels” into the viewer.

plt.imshow(interactive.screenshot())
plt.axis('off')

Select “point8_labels” in the list of layers. Then, we open the “Scatter” Widget by using the menu bar and going to Plugins > napari-spatialdata > Scatter. This loads the AnnData object associated with that layer into the “Scatter” Widget.

plt.imshow(interactive.screenshot())
plt.axis('off')

Then, we can now pick specific x-axis, y-axis and color values to visualize in the scatterplot.

In the example below, we’re visualizing the UMAP (Uniform Manifold Approximation and Projection) coordinates of two different axes and coloring it by cell size.

plt.imshow(interactive.screenshot())
plt.axis('off')

After plotting, it is possible to interactively select clusters and export it to AnnData.

In the example below, we used the cursor to select a cluster on the left half of the scatterplot. We can export it into AnnData by clicking on the “Annotate” button.

plt.imshow(interactive.screenshot())
plt.axis('off')

After exporting, we can now view the selected points with the View widget. Close the Scatter Widget and from the menu bar, go to Plugins > napari-spatialdata > View. You should be able to observe “my_annotation” under “Observations:”. This is selected points we exported in the previous step.

Double clicking on “my_annotation” loads it as a layer in the Napari viewer.

plt.imshow(interactive.screenshot())
plt.axis('off')