# Below code loads napari to notebook for screenshot purposes
# All functions done on the viewer window3
import warnings
import matplotlib.pyplot as plt
import napari
from IPython import get_ipython
from loguru import logger
class ScreenshotContext:
def __enter__(self):
get_ipython().run_line_magic("matplotlib", "inline")
def __exit__(self, exc_type, exc_value, traceback):
get_ipython().run_line_magic("matplotlib", "qt")
plt.rcParams["figure.figsize"] = (20, 20)
warnings.filterwarnings("ignore")
logger.remove()
Getting started#
The two main options for installing PRISM
are:
Directly as a python package hosted on pypi, or directly from the Github repository
Within the napari application as a plugin hosted on napari-hub (later transitioning to a community-run implementation)
Installation#
via pip installation#
Install via pypi:
pip install napari-prism
Install via github by cloning and installing the repository locally:
git clone https://github.com/clinicalomx/napari-prism
Change to the directory of the cloned repo
pip install .
via napari-hub#
If napari is not installed in an environment see the following guide. Currently, the package only supports napari versions <=0.4.19.post1.
Open the napari application i.e. by running:
python -m napari
In the application toolbar, navigate
Plugins
>Install/Uninstall Plugins...
In the
Plugin Manager
search fornapari-prism
, and clickInstall
.
Opening the napari application#
From the command line / terminal: python -m napari
From a jupyter notebook cell:
viewer = napari.Viewer()
Usage and entry points#
Designed as a modular package, there are multiple ways to launch and use PRISM
, depending on the initial input.
As an example, we use a previously published and analysed dataset from Monkman et al. (2024), which is a FFPE tissue microarray of samples from a Non-Small Cell Lung Cancer (NSCLC4301) cohort, imaged through the Akoya Phenocycler™-Fusion platform at 36-plex.
Starting from raw image files (.qptiff)#
Open the napari application
Navigate the file menu:
File
>Open with Plugin
>Open Files(s)...
Select the .qptiff image file >
Open
|
In
Choose reader
, ensurenapari napari-prism
is selected >Ok
This creates a barebones spatialdata.SpatialData
object saved to disk as a .zarr store containing the sole raw image stored in a multiscale/pyramidal format.
The SpatialData object is saved to disk to the same directory as a .zarr file.
Note that this process make take awhile depending on the size of the image.
Once complete, the SpatialData (.zarr file) will be imported in the viewer as per steps below.
Starting from on-disk SpatialData objects (.zarr)#
If importing from a .qptiff file, the below steps will be done automatically.
If importing from a .zarr file:
Navigate
File
>Open with Plugin
>Open Folder...
Select the .zarr folder >
Open
(don’t select any of its child folders like the images or tables folder)
|
In
Choose reader
, selectnapari napari-prism
>Ok
Launching the .zarr folder with napari-prism
does two things:
It launches napari-spatialdata plugins. It launches a base widget (bottom left) which the user selects SpatialData elements to add as layers, the
View
plugin to visualise attributes of those elements, and theScatter
plugin to visualiseAnnData
attributes.It launches the
napari-prism
widgets, containing theTMA Image Analysis
andAnnData Analysis
(covered in the next two notebooks).
These widgets will be organised in tabs (bottom right).
The window will look something like this:
with ScreenshotContext():
plt.imshow(viewer.screenshot(canvas_only=False))
plt.axis("off")
plt.show()
The user can use the SpatialData Elements
(bottom left) and View (napari-spatialdata)
widgets (tab on the bottom right) to visualise components of the SpatialData object.
For example, they can visualise the loaded and parsed .qptiff image
Select the
global
(pixels) coordinate systemSelect and double-click the raw .qptiff image
NSCLC430
that appears inElements:
Visualise a channel of choice by double clicking the
Vars
element, i.e.)DAPI
with ScreenshotContext():
plt.imshow(viewer.screenshot(canvas_only=False))
plt.axis("off")
plt.show()
We also provide a way to visualise channels as multiple colors:
Select the channel vars to view in the
View (napari-spatialdata widget)
Select the original image layer
NSCLSC4301
. Make this invisible by clicking the eye symbol of this layer.Select the
TMA Image Analysis (napari-prism)
widget tab in the bottom rightSelect the
Utils
tab at the top of this widgetClick
Add current view as standalone
Click the
NSCLC View: (channel)
layer in the layer list on the leftChange the image properties using the layer controls on the top right:
Opacity: Transparency of the image
Contrast limits: Slider to threshold image intensities to a lower (first circle) and upper (second circle) bound
Gamma: Visualised ‘brightness’ shown on the monitory to the user. Decrease to make brighter.
Colormap: Change this to color intensity by color
Repeat steps 1-7 for every channel(s) you wish to visualise
As an example, we visualise:
DAPI in blue
E-cadherin in green
CD68 in magenta
with ScreenshotContext():
plt.imshow(viewer.screenshot(canvas_only=False))
plt.axis("off")
plt.show()
Then, E-cadherin as a green colormap:
with ScreenshotContext():
plt.imshow(viewer.screenshot(canvas_only=False))
plt.axis("off")
plt.show()
Then, CD68 as a magenta colormap:
with ScreenshotContext():
plt.imshow(viewer.screenshot(canvas_only=False))
plt.axis("off")
plt.show()
Next Steps#
For more information on how to use the viewer widgets, please see the original napari-spatialdata documentation.
See the next section to learn how to process and analyse the raw tissue microarray image.