01 Why Jupyter?
Imagine you are analysing RNA-seq data from Sorghum bicolor. You load a counts matrix, filter low-expressed genes, run a PCA, and produce a volcano plot. If you do all of this in a plain Python script (.py), you see the final output — but nothing in between. You cannot easily pause after the PCA step, inspect the result, adjust a parameter, and continue. You have to re-run everything.
This is the problem Jupyter solves. A Jupyter notebook is an interactive document that combines live code, its output, explanatory text, equations, and figures — all in one file. You run one cell at a time, see the result immediately, and then decide what to do next. This matches how exploratory bioinformatics actually works.
RNA-seq analysis, GWAS, and genomic selection involve many decision points: which samples to exclude, which normalisation method to choose, what significance threshold to set. These decisions are easier to make and easier to document when your code, your reasoning, and your plots all live in the same notebook. Jupyter turns analysis into a reproducible, readable story rather than a black-box script.
Jupyter notebooks are used by the biggest bioinformatics projects in the world — including the Human Cell Atlas, the Pan-Cancer Analysis of Whole Genomes, and most machine-learning genomics pipelines. They are also the standard format for sharing analyses on GitHub, where your notebook renders beautifully in the browser with no setup needed by the reader.
02 Notebook vs Script: When to Use Which
Both notebooks and scripts have their place in a bioinformatics workflow. The key is knowing which tool fits the job.
| Situation | Use a Notebook | Use a Script |
|---|---|---|
| Exploratory analysis | ✅ Ideal — inspect data step by step | ❌ Re-run everything each time |
| Visualisation | ✅ Inline figures, easy iteration | ⚠ Must save figures separately |
| Sharing results | ✅ Renders on GitHub, nbviewer | ❌ Reader must run the script |
| Production pipeline | ⚠ Can be automated with papermill | ✅ Ideal — fast, scriptable, schedulable |
| Snakemake rule | ❌ Not directly compatible | ✅ Designed for script-based rules |
| Teaching / documentation | ✅ Text + code + output together | ❌ Requires separate documentation |
A common professional pattern: use a Jupyter notebook to explore your data, decide on parameters, and produce figures for a paper. Once you are happy with the workflow, convert the key steps into a Python script and wrap it in Snakemake (Module 13) for automated batch processing. The notebook becomes your lab book; the script becomes your production tool.
03 Anatomy of a Notebook
A Jupyter notebook (.ipynb) is a JSON file on disk that stores a sequence of cells. Each cell has a type and can be run independently. Here is what a real notebook looks like in JupyterLab:
Loading normalised counts and computing PCA.
*Data: JLU Gießen field trial 2024*
import matplotlib.pyplot as plt
counts = pd.read_csv('counts_normalised.csv', index_col='gene_id')
counts.head()
Sobic.001 245.3 312.1 198.7 287.4
Sobic.002 1204.8 998.2 1312.5 1089.3
...
counts.values.flatten().plot.hist(bins=50)
plt.xlabel('Normalised count')
plt.show()
The three fundamental building blocks:
| Cell type | What it contains | Keyboard shortcut to run |
|---|---|---|
| Code cell | Python (or R, Bash) code that executes against the kernel | Shift+Enter |
| Markdown cell | Formatted text, headings, bullet points, LaTeX equations, links | Shift+Enter |
| Raw cell | Plain text that is not executed or rendered (used with nbconvert) | — |
The .ipynb file format is simply JSON. Every cell, its code, its outputs, and its metadata are stored as key-value pairs. This means notebooks are version-controllable with Git — though large output cells (especially images) can inflate file size, so jupyter nbconvert --clear-output before committing is good practice.
04 Install JupyterLab with conda
We install JupyterLab into our existing bioinfo-py conda environment so it has access to all our bioinformatics packages (pandas, biopython, matplotlib, etc.) without any extra configuration.
If you install JupyterLab outside your environment (e.g. with pip install jupyterlab in the base environment), it will not see the packages you installed in bioinfo-py. By installing it inside the environment, the Jupyter kernel automatically has access to every package in that environment — numpy, pandas, biopython, scikit-learn — with no extra configuration.
# Step 1: Activate your bioinformatics conda environment conda activate bioinfo-py # Step 2: Install JupyterLab and the ipykernel package # ipykernel registers this environment as a Jupyter kernel conda install -c conda-forge jupyterlab ipykernel -y # Step 3: Confirm the installation jupyter lab --version # Expected: 4.x.x
ipykernel is the Python package that connects a Python environment to a Jupyter notebook. When you run a code cell, JupyterLab sends the code to the kernel via a network socket, the kernel executes it, and sends the result back. Without ipykernel, JupyterLab cannot run Python code in your environment. Think of it as the bridge between the browser-based interface and your Python installation.
If you want to use a separate, cleaner environment specifically for Jupyter (recommended for larger projects), create one now:
# Optional: create a dedicated Jupyter environment conda create -n jupyter-bioinfo python=3.11 jupyterlab ipykernel \ pandas numpy matplotlib seaborn biopython -y conda activate jupyter-bioinfo # Register this environment as a named kernel # The --name flag sets the internal kernel ID # The --display-name flag sets what you see in the JupyterLab UI python -m ipykernel install --user \ --name jupyter-bioinfo \ --display-name "Python (bioinfo)" # List registered kernels to confirm jupyter kernelspec list # Available kernels: # jupyter-bioinfo /home/shajedur/.local/share/jupyter/kernels/jupyter-bioinfo # python3 /usr/local/share/jupyter/kernels/python3
conda install over pip install for JupyterLab itself. conda resolves library dependencies (including native libraries like zeromq that Jupyter depends on) more reliably than pip in a conda environment. If conda is slow, use mamba install as a faster drop-in replacement.
05 Launch JupyterLab & Create Your First Notebook
Launching JupyterLab opens a local web server (usually at http://localhost:8888) and opens a browser tab with the full JupyterLab interface. Your files are not uploaded anywhere — everything runs locally on your machine.
# Create and move into your project directory mkdir -p ~/jupyter-bioinfo-notebooks cd ~/jupyter-bioinfo-notebooks # Activate your environment (if not already active) conda activate bioinfo-py # Launch JupyterLab # --no-browser: do not auto-open browser (useful on servers) # --port: specify a port (default 8888) jupyter lab # [I 2024-...] JupyterLab extension loaded from ... # [I 2024-...] Serving notebooks from local directory: /home/shajedur/jupyter-bioinfo-notebooks # [I 2024-...] Jupyter Server 2.x is running at: # [I 2024-...] http://localhost:8888/lab?token=abc123... # JupyterLab will open in your default browser automatically # To stop the server: press Ctrl+C in the terminal
Running jupyter lab starts a lightweight Python web server called Jupyter Server on your machine. Your browser connects to this server at localhost:8888 and renders the JupyterLab interface as a web application. The token in the URL (?token=abc123...) is a one-time security key that prevents other users on the same machine from accessing your notebooks. Your files never leave your computer — you are simply using your browser as a display for a local application.
Once JupyterLab opens in your browser, create your first notebook:
- In the Launcher tab, click Python 3 (ipykernel) under the Notebook section.
- A new untitled notebook opens. Click the filename at the top (
Untitled.ipynb) and rename itlesson-01-intro.ipynb. - Click the first code cell and type:
print("Hello, Sorghum!") - Press Shift+Enter to run the cell. The output appears immediately below.
- Press Esc then M to convert the next cell to Markdown.
- Type
## My first bioinformatics notebookand press Shift+Enter.
06 Kernels Explained
A kernel is the computational engine behind a notebook. When you create a new notebook, you choose a kernel — this determines which programming language and which environment runs your code. Understanding kernels is essential for bioinformatics because you often need different environments for different analyses.
| Kernel | Language | Typical bioinformatics use |
|---|---|---|
| ipykernel (Python 3) | Python | pandas, biopython, scikit-learn, scanpy, tensorflow |
| IRkernel | R | DESeq2, ggplot2, rrBLUP, BGLR — run R in a notebook |
| bash_kernel | Bash | Run shell commands, GATK, samtools inline |
| xeus-python | Python | Faster Python kernel with better debugger |
Your thesis uses both R (rrBLUP, BGLR) and Python (data wrangling, ML). With Jupyter, you can have two notebooks open side by side — one with an R kernel running your genomic prediction models, one with a Python kernel handling your pandas DataFrames. Both notebooks share the same file system, so an R script can write a CSV that Python immediately reads. This is the hybrid workflow that professional computational biologists use daily.
To install the R kernel (IRkernel) for use with Jupyter:
# In R (not bash) — install IRkernel install.packages('IRkernel') # Register the R kernel with Jupyter # user = TRUE installs for your user only (no sudo needed) IRkernel::installspec(user = TRUE) # Back in bash: confirm R kernel is registered # $ jupyter kernelspec list # Available kernels: # ir /home/shajedur/.local/share/jupyter/kernels/ir # python3 /usr/local/share/jupyter/kernels/python3
After installing IRkernel, when you create a new notebook in JupyterLab you will see both Python 3 and R as kernel options. Lesson 7 (Genomic Selection Data) uses the R kernel to explore your BPV output files directly in a notebook.
htop in a terminal while the notebook runs.
07 Exercises
Complete these exercises before moving to Lesson 2. They consolidate everything covered in this lesson.
Activate your bioinfo-py conda environment, install JupyterLab and ipykernel, and run jupyter lab --version. Paste the version number in a Markdown cell of your first notebook.
Show answer
conda activate bioinfo-pyconda install -c conda-forge jupyterlab ipykernel -yjupyter lab --versionExpected output:
4.x.x. Create a Markdown cell in your notebook and type: JupyterLab version: 4.x.x, then press Shift+Enter to render it.
Create the directory ~/jupyter-bioinfo-notebooks, navigate into it, and launch JupyterLab from that directory. Why does launching from the project directory matter?
Show answer
mkdir -p ~/jupyter-bioinfo-notebookscd ~/jupyter-bioinfo-notebooksjupyter labLaunching from the project directory sets this folder as the root directory of the JupyterLab file browser. All relative file paths in your notebooks (e.g.
pd.read_csv('data/counts.csv')) are resolved relative to this directory. If you launch from ~, relative paths won't find your data files.
In your lesson-01-intro.ipynb notebook, create: (a) a Markdown cell with a heading "Sorghum bicolor Analysis" and one bullet point, and (b) a code cell that prints the Python version and the platform (use the sys and platform modules). Run both cells.
Show answer
## Sorghum bicolor Analysis- Exploring genomic selection data from JLU Gießen field trialCode cell:
import sys, platformprint(f"Python: {sys.version}")print(f"Platform: {platform.platform()}")Press Shift+Enter on each cell. The Markdown cell renders as formatted text; the code cell prints system information below it.
Open a terminal (either inside JupyterLab via File → New → Terminal, or in a separate terminal window) and run jupyter kernelspec list. How many kernels are registered? What are their names and paths?
Show answer
jupyter kernelspec listYou should see at least
python3 pointing to your conda environment's Python. If you installed IRkernel, you will also see ir. The path shown is where the kernel's kernel.json configuration file lives — this file tells Jupyter how to start the kernel process.