✦ Module 19 · Phase 3 — Advanced & Specialised

What is Jupyter & Why Bioinformaticians Use It

Understand the notebook paradigm, install JupyterLab via conda, and launch your first interactive analysis environment.

📅 Week 25 · Lesson 1 of 10
Lesson 1 45 minutes 🐍 Python 🌱 Beginner 📦 conda · JupyterLab

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.

Why this matters in bioinformatics

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.

💡 JupyterLab vs Jupyter Notebook: There are two interfaces. The older "Jupyter Notebook" (classic) opens notebooks in a simple single-tab browser window. JupyterLab is the modern IDE-like interface with a file browser, multiple tabs, terminal panels, and extensions. We use JupyterLab throughout this module — it is what you will encounter in professional settings.

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
The bioinformatics workflow split

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:

sorghum-rnaseq-exploration.ipynb — JupyterLab
MARKDOWN CELL
## Sorghum BPV — RNA-seq Exploration
Loading normalised counts and computing PCA.
*Data: JLU Gießen field trial 2024*
CODE CELL [1]
import pandas as pd
import matplotlib.pyplot as plt
counts = pd.read_csv('counts_normalised.csv', index_col='gene_id')
counts.head()
OUTPUT
SRG_001 SRG_002 SRG_003 SRG_004
Sobic.001 245.3 312.1 198.7 287.4
Sobic.002 1204.8 998.2 1312.5 1089.3
...
CODE CELL [2]
# Quick histogram of expression values
counts.values.flatten().plot.hist(bins=50)
plt.xlabel('Normalised count')
plt.show()

The three fundamental building blocks:

Cell typeWhat it containsKeyboard shortcut to run
Code cellPython (or R, Bash) code that executes against the kernelShift+Enter
Markdown cellFormatted text, headings, bullet points, LaTeX equations, linksShift+Enter
Raw cellPlain 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.

📌 Cell execution order matters. Cells are numbered in the order they were run, not the order they appear in the file. A cell at the bottom can be run before a cell at the top. This is both the power and the danger of notebooks — always run Kernel → Restart & Run All before sharing a notebook to ensure top-to-bottom reproducibility.

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.

Why install inside the conda environment?

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.

📁 Run from: any location — we are managing conda environments
bash
# 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
What is ipykernel?

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:

📁 Run from: any location
bash
# 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 vs pip: Always prefer 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.

📁 Run from: ~/jupyter-bioinfo-notebooks (your project folder)
bash
# 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
What is happening when you run "jupyter lab"?

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:

  1. In the Launcher tab, click Python 3 (ipykernel) under the Notebook section.
  2. A new untitled notebook opens. Click the filename at the top (Untitled.ipynb) and rename it lesson-01-intro.ipynb.
  3. Click the first code cell and type: print("Hello, Sorghum!")
  4. Press Shift+Enter to run the cell. The output appears immediately below.
  5. Press Esc then M to convert the next cell to Markdown.
  6. Type ## My first bioinformatics notebook and press Shift+Enter.
⌨️ Two modes in Jupyter: Command mode (blue border) — navigate between cells, add/delete cells, change cell type. Edit mode (green border) — type inside a cell. Press Esc to enter Command mode, Enter to enter Edit mode. We cover all keyboard shortcuts in Lesson 2.

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.

KernelLanguageTypical bioinformatics use
ipykernel (Python 3)Pythonpandas, biopython, scikit-learn, scanpy, tensorflow
IRkernelRDESeq2, ggplot2, rrBLUP, BGLR — run R in a notebook
bash_kernelBashRun shell commands, GATK, samtools inline
xeus-pythonPythonFaster Python kernel with better debugger
Why does this matter for your sorghum analysis?

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:

📁 Run from: any location — open R console or RStudio
R
# 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.

⚠️ Kernel is dead / not starting? This usually means the kernel process crashed. Click Kernel → Restart Kernel. If it keeps crashing, the most common cause is running out of RAM (loading a very large dataset). Check memory usage with htop in a terminal while the notebook runs.
Advertisement Support free bioinformatics education

07 Exercises

Complete these exercises before moving to Lesson 2. They consolidate everything covered in this lesson.

1
Install and verify JupyterLab

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-py
conda install -c conda-forge jupyterlab ipykernel -y
jupyter lab --version

Expected 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.
2
Create your project directory and launch

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-notebooks
cd ~/jupyter-bioinfo-notebooks
jupyter lab

Launching 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.
3
Notebook with two cell types

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
Markdown cell:
## Sorghum bicolor Analysis
- Exploring genomic selection data from JLU Gießen field trial

Code cell:
import sys, platform
print(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.
4
List registered kernels

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
Run: jupyter kernelspec list

You 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.
Advertisement shopnilacademy.com