Group Work 1: Building your Own Segmentation and Spot Detection Pipeline#
Let’s now consolidate what you have learned! These exercises will walk you through how to create your own Jupyter Notebook containing code that segments images with Cellpose and detects spots with Spotiflow.
The images we will use for this exercise can be downloaded from the Group Work 1 Dataset.
To go through these exercises, you need to create a new folder named bobiac_group_work. In the instruction below, we will assume this folder is on your Desktop but you can choose a different location if you prefer.
Step 1#
Create a new Jupyter Notebook with uv’s juv tool
Open a new Terminal or PowerShell and navigate to the
bobiac_group_workfolder.Inside the
bobiac_group_workfolder, create a new folder namedgroup_work_1and navigate into it.Inside the
group_work_1, create a new Jupyter Notebook namedgroup_work_1.ipynbusinguv’sjuvtool.Run the notebook in your browser using
juv.\Close the notebook tab in your browser and stop the notebook from the terminal (
cmd + corctrl + c) before proceeding to Step 2.
Solution
Open the Terminal or PowerShell.
cd .../Desktop/bobiac_group_workmkdir group_work_1cd .../Desktop/bobiac_group_work/group_work_1uvx juv init group_work_1.ipynbuvx juv run group_work_1.ipynbClose the notebook tab in your browser and stop the notebook from the terminal (
cmd + corctrl + c)
Step 2#
Add dependencies to the Jupyter Notebook with juv
In your notebook created in Step 1, add your dependencies using
juv.Note
It is up to you which dependencies you want to add based on what we covered during the course. If you forget a dependency, you can always close the notebook in both the browser and the terminal, add the dependency, and re-run the notebook.
Run the notebook with
juv.Import the libraries in the first cell.
Run the cell to confirm that they are installed and can be imported without errors.
Note
If you would rather work in Google Colab instead of running the notebook locally, you can copy the .ipynb file you created to your Google Drive and open it from the Colab website.
Keep in mind that Colab does not support the PEP 723 inline script metadata that juv uses to manage dependencies. This means you will need to add a !pip install <package_name> cell for each dependency, and run it before the cell that imports the libraries.
Solution
cd .../Desktop/bobiac_group_work/group_work_1(the folder created in Step 1)uvx juv add group_work_1.ipynb cellpose tqdm tifffile spotiflowuvx juv run group_work_1.ipynbAdd a new
codecell in the notebook (+button)Within this cell, import the necessary libraries:
from pathlib import Path from cellpose import core, io, models, plot from cellpose.models import MODEL_DIR from tqdm import tqdm import csv import tifffile from spotiflow.model import Spotiflow import numpy as np
Run the cell to confirm that the libraries are imported without errors.
Step 3#
Run Cellpose on the full dataset
In this step you need to add the code that segments nuclei and cytoplasm of all the images in the dataset using Cellpose and saves the segmentation as a .tif file.
You need to segment both the nuclei and cytoplasm of the images. The nuclei are in channel 0 and the cytoplasm is in channel 1.
Tip
To get the nuclei segmentation, you can pass only the nuclei channel (channel 0) to the Cellpose eval method. To get the cytoplasm segmentation, you can pass both channels (0 and 1).
For each step, create a new
codecell in the notebook (+button).Within the cell, add the necessary code.
Solution
Step 4#
Run Spotiflow on the full dataset
In this step you need to add the code that detects spots in the 4th channels of all the images in the dataset using Spotiflow and saves a .csv file of their coordinates.
For each step, create a new
codecell in the notebook (+button).Within the cell, add the necessary code.