Group Work 2: Analysing Oscillations in Time-Series Images#
In this exercise, you will build a small analysis workflow in a Jupyter Notebook to investigate whether the expression of a gene oscillates over time. The notebook is based on the example in Solution Notebook, and it uses time-resolved microscopy images together with cell and nucleus label masks.
The images we will use for this exercise can be downloaded from the Group Work 2 Dataset.
To go through this exercise, create a new folder named bobiac_group_work. In the instructions below, we 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_2and navigate into it.Inside
group_work_2, create a new Jupyter Notebook namedoscillations.ipynbusingjuv.Run the notebook in your browser with
juv.Close the notebook tab in your browser and stop the notebook from the terminal (
cmd + corctrl + c) before continuing to Step 2.
Solution
Open the terminal or PowerShell.
cd .../Desktop/bobiac_group_workmkdir group_work_2cd .../Desktop/bobiac_group_work/group_work_2uvx juv init oscillations.ipynbuvx juv run oscillations.ipynbClose the notebook tab in your browser and stop the notebook from the terminal (
cmd + corctrl + c)
Step 2#
Add dependencies to the notebook with juv
In your notebook created in Step 1, add the dependencies you need for the analysis.
Run the notebook with
juv.Import the libraries in the first code cell.
Run the cell to confirm that the imports work without errors.
The analysis in the example notebook uses the following packages:
matplotlibnumpypandasseabornscikit-imagescipytifffileimagecodecsbobiac_tools
Note
If you prefer to work in Google Colab instead of locally, copy the .ipynb file to your Google Drive and open it from the Colab website. In that case, you will need to add a !pip install <package_name> cell for each dependency before importing the libraries.
Solution
cd .../Desktop/bobiac_group_work/group_work_2Add the dependencies:
uvx juv add oscillations.ipynb matplotlib numpy pandas seaborn scikit-image scipy tifffile imagecodecs uvx juv add oscillations.ipynb "bobiac_tools @ git+https://github.com/bobiac/bobiac-tools.git"
uvx juv run oscillations.ipynbIn the first code cell, add imports such as:
from pathlib import Path import matplotlib.pyplot as plt import pandas as pd import seaborn as sns import skimage import tifffile from bobiac_tools import overlay_labels
Run the cell to confirm that the libraries import without errors.
Step 3#
Load and inspect the time-series images
In this step, you will load the image files and the segmentation masks and inspect the data visually.
Create a new code cell in the notebook.
Download the dataset folder that contains the time-lapse file
F01_1615_tcyx.tif.For the
F01_1615_tcyx.tiffile, display the first eight time points of the last channel in the as a grid of images.In the same dataset folder, there is a
F01_1615_tcyx_cell_labels.tiffile (labeled mask of the cells) and aF01_1615_tcyx_nuclei_labels.tiffile (labeled mask of the nuclei). Visualize these masks as an overlay
The example notebook uses the data in the course repository under the images/ and masks/ folders for the time-series example.
Solution
See Solution Notebook for a worked example.
Step 4#
Measure nuclear intensity for the first time point
In this step, you will analyse the first image and quantify the intensity of each nucleus.
Load the first time point of the last channel in the
F01_1615_tcyx.tiffile.Remove objects touching the border of the image.
Measure the intensity of each nucleus with
skimage.measure.regionprops_table.Subtract the background intensity from the measurements and inspect the resulting values.
Tip
You can use the same workflow as in the earlier measurement notebooks: load the image, apply a mask, extract region measurements, and store the results in a pandas.DataFrame.
Solution
See Solution Notebook for a worked example.
Step 5#
Perform quality control and analyse all time points
Now you will turn the workflow into a batch analysis over all 16 images.
Check the measurements for artifacts, for example by plotting the distribution of background-corrected intensities.
Overlay the measured values on the image and inspect whether any nuclei look suspicious.
Loop through all time points, measure the intensity of each nucleus, and add a
timecolumn.Combine all measurements into a single
DataFrame.
Solution
See Solution Notebook for a worked example.
Step 6#
Visualise the oscillations and estimate the frequency
In this final step, you will answer the main question: what is the frequency of the oscillations?
Use
sns.lineplotto visualise the intensity of each nucleus over time.Add a second plot showing the average signal across cells.
Estimate the oscillation frequency from the pattern you observe.
Write a short conclusion in a markdown cell.
Solution
See Solution Notebook for a worked example.
Bonus#
Try a nuclear/cytoplasmic ratio
If you want an extra challenge, replace the nuclear intensity measurement with a ratio of nuclear intensity divided by cytoplasmic intensity. This can sometimes make the oscillation easier to interpret.