Workflows

Notebooks vs pipelines for reproducible work

Where notebooks help, where they hide state, when a pipeline is worth the complexity and how to combine the two.

A notebook is an interactive document that mixes code, output and explanation. A pipeline is a scripted workflow that runs a defined sequence of steps. Both can be reproducible, and both can fail to be.

What reproducibility means

A reproducible analysis gives the same result when repeated with the same data, code and environment. A reusable analysis can also be run on new data with the same logic.

Reproducibility depends on the code, the software versions, the parameters, the input data and the order of steps. A notebook that works on one laptop may fail on another because of a different package version or a missing file.

Notebooks

Notebooks are good for exploration, teaching and communication. They let you run a step, inspect the output and adjust the next step. They keep the code and the narrative together.

The risk is hidden state. Cells can be run out of order, and the displayed output may come from an earlier version of the code. A notebook that looks clean may not reproduce from top to bottom.

To reduce the risk, restart the kernel and run all cells before sharing. Keep the notebook focused. Move reusable functions into a module and test them.

Pipelines

A pipeline defines the steps and their dependencies. It can be rerun from start to finish, often with a workflow manager that tracks which steps need to be repeated when an input changes.

Pipelines are good for production, large datasets and analyses that must be repeated across samples. They make the order explicit and can parallelise independent steps.

The risk is complexity. A pipeline with many configuration files and hidden defaults can be hard to understand. Document the inputs, the outputs and the parameters.

A hybrid approach

A common pattern is to explore in a notebook, then move the stable steps into a script or pipeline. The notebook records the reasoning; the pipeline runs the final analysis.

Keep the notebook and the pipeline in the same repository. Record which notebook led to which pipeline and which version produced the final figure.

Version control

Put code, notebooks, configuration and documentation in version control. Commit small changes with clear messages. Use branches for experiments if needed.

Notebooks in version control can produce noisy diffs because the output is stored in the file. Clear the output before committing, or use a tool that strips it. Keep the executed version separately if the output is part of the record.

Environments

Record the software environment. A lock file, a container or a list of package versions makes it possible to recreate the environment.

An environment that is not recorded is a hidden dependency. A script that works today may fail after an update. Pin the versions that matter and test the environment on a clean machine when possible.

Testing

A pipeline should have a small test dataset and an expected output. The test does not need to cover every branch; it needs to catch a broken step.

For a notebook, a smoke test that runs from top to bottom on a small input is useful. For a pipeline, a test that checks the output files and a few key values is enough.

Documentation

Document the inputs, the outputs, the parameters and the dependencies. A README that says "run the script" is not enough if the script needs a reference genome and a sample sheet.

Record the decisions that are not obvious: why a parameter was chosen, why a sample was excluded, why a step was run in a different order. Those decisions are part of the method.

When to use which

Use a notebook when the analysis is exploratory, when the narrative matters, or when you are learning. Use a pipeline when the analysis must be repeated, when there are many samples, or when the steps are stable.

Use a hybrid when you need both. The important thing is that the final result can be traced to code, data and parameters.

Workflow managers

A workflow manager such as Snakemake or Nextflow describes the steps as rules with inputs and outputs. It can rerun only the steps whose inputs changed and can run independent steps in parallel.

The manager does not make a workflow reproducible by itself. The rules, the containers and the parameters still need to be recorded. A workflow that depends on a file in someone's home directory is not portable.

Start with a small workflow and a test dataset. A complex workflow that has never been run end to end is not ready for production.

Notebook hygiene

Keep one notebook per question. Clear the output before committing. Put reusable code in a module and import it.

Use a deterministic seed for random steps. Record the seed. A result that changes between runs because of randomness is not reproducible unless the seed is fixed.

If a notebook takes a long time to run, save the intermediate outputs and document how to regenerate them. Do not rely on a cell that was run once and never repeated.

Reporting

Report the code repository, the commit or tag, the environment file and the command used to produce the final result. For a notebook, state the kernel and the package versions.

If the analysis was run on a cluster, report the scheduler and the resources. A result that only runs on one machine is not portable.

Key points

  • Reproducibility depends on code, versions, parameters and data.
  • Notebooks are good for exploration; hidden state is the risk.
  • Pipelines are good for repeated, multi-sample work.
  • Record the environment and the inputs.
  • Move stable steps from notebooks into scripts.

Common mistakes

  • Sharing a notebook that was not run from top to bottom.
  • Pinning no versions and hoping the environment stays the same.
  • Keeping the final script only on one laptop.
  • Documenting the steps but not the parameters.
  • Using a pipeline without a small test.

When to ask for help

If an analysis must be repeated across samples, if a reviewer cannot reproduce a figure, or if the environment is unstable, ask for a review. You can order an analysis or read the reproducible analysis guide. The Reproducible Bioinformatics Pipelines course covers workflow managers, and the data management guide covers the files.

Sources and further reading

When to ask for help. If your data or design do not fit a tutorial, order an analysis and we will reply with a fixed price.

Written by the Solagene team for research and education. Found an error? Tell us and we will correct it.