nextflow-snakemake.md
258 lines · skills/latchbio-integration/references/nextflow-snakemake.md at 5f2bc03
Most marks come from matching words in the file, so treat them as pointers.
Nextflow and Snakemake Integration
Latch supports Python, Nextflow, and Snakemake workflows, but their packaging paths are not interchangeable. Confirm the SDK version and choose one track before generating files.
Raw lines 1 to 6Nextflow: Documented SDK Wrapper Path
Raw lines 7 to 8Prerequisites
- A runnable Nextflow pipeline
- A
nextflow_schema.json - Containers or a documented execution profile for every process
- A pinned Latch SDK
Install:
uv pip install "latch==2.77.1"Raw lines 9 to 21Generate metadata
latch generate-metadata nextflow_schema.json --nextflowCurrent generation creates:
latch_metadata/
├── __init__.py
└── generated.pygenerated.pyis regenerated from the schema. Do not edit it.- Put persistent custom metadata and flow changes in
latch_metadata/__init__.py. - Re-run generation after changing
nextflow_schema.json. - Review inferred file, enum, default, and required types before registration.
SDK 2.67.0 changed Nextflow generation to use one generated dataclass containing all parameters and a generated base flow. Older parameters.py examples may no longer match the generated layout.
Register
The currently documented wrapper command is:
latch login
latch register . \
--nf-script main.nf \
--nf-execution-profile docker,testRegistration generates a Latch workflow wrapper and latch.config. The exact entrypoint location depends on the generation path and SDK version.
Important:
- If a root
Dockerfileexists, registration uses it. - Otherwise Latch can generate a Dockerfile under
.latch/. - Passing
--nf-scriptagain can regenerate and overwrite wrapper code. - After intentionally customizing a generated entrypoint, re-register without
--nf-scriptto preserve it. - Keep custom code in a separate module when possible.
Generate an entrypoint explicitly
SDK 2.77.1 also exposes:
latch nextflow generate-entrypoint . \
--nf-script main.nf \
--execution-profile docker,test \
--output wf/custom_entrypoint.pyThis requires a valid NextflowMetadata object in the metadata root.
Experimental Forch-only registration
The CLI also has:
latch nextflow register . --script-path main.nfThe official CLI guide marks this command experimental and only applicable to Forch, Latch's architecture for running Nextflow in the user's own AWS account. It is not a general alternative to latch register --nf-script. Use it only for a configured Forch/BYOC project with current Latch guidance.
Nextflow configuration rules
- Define every process container.
- Use profiles for environment-specific settings rather than editing the pipeline for Latch.
- Keep Latch's generated
latch.configin the effective config chain. - Use the official Latch shared-storage guidance for processes that need a common work directory.
- Configure private registries through Latch's supported credentials path.
- Follow the Latch GPU guide for process accelerators; do not translate Python task decorators into Nextflow resource syntax.
- Set
NextflowRuntimeResources.storage_gibfor the runtime/shared filesystem, not just final outputs. - Understand storage-retention cost before increasing
storage_expiration_hours.
Debugging
latch register --staging .
latch develop .
latch nextflow attach --execution-id <execution-id>Within latch develop, the production storage initializer is unavailable. Follow the official debug-mode guidance: use the local executor, bypass the initializer in debug mode, use a compatible Latch Nextflow base image, and reduce process resources.
Snakemake: Choose a Compatibility Track
The current docs and current stable package expose different Snakemake tracks. Do not mix them.
Raw lines 123 to 127Track A: legacy flags in 2.77.1 source (documentation conflict)
The 2.77.1 wheel still exposes the snakemake extra, legacy metadata classes, generate-metadata --snakemake, and register --snakefile. However, the official CLI guide marks the Snakemake metadata and registration flags deprecated and says metadata generation no longer works for latch >= 2.55.0.a6.
Treat this as an unresolved source/documentation conflict. The commands below are useful when maintaining a legacy project already known to use this path, but should not be presented as a supported new-project flow without confirming with current Latch documentation or support.
Use Python 3.11 for the broadest compatibility with the pinned Snakemake 7.x dependency:
uv venv --python 3.11
source .venv/bin/activate
uv pip install "latch[snakemake]==2.77.1"Generate metadata from the workflow config:
latch generate-metadata config.yaml --snakemakeRegister:
latch register . --snakefile SnakefileRelevant options:
latch register . \
--snakefile Snakefile \
--metadata-root latch_metadata \
--cache-tasksUse the current SnakemakeMetadata, SnakemakeParameter, FileMetadata, EnvironmentConfig, and DockerMetadata APIs from latch.types.metadata. Inspect their signatures before generating hand-written metadata.
Track B: official Snakemake v2 tutorial
The current Snakemake v2 tutorial is a compatibility-specific path. At the time of this refresh, it explicitly requires:
uv venv --python 3.11
source .venv/bin/activate
uv pip install "latch==2.62.1a2"It uses imports such as:
from latch.types.metadata.snakemake_v2 import SnakemakeV2Metadataand commands such as:
latch snakemake generate-entrypoint .
latch dockerfile --snakemake -c environment.yaml . -f
latch register -y .Those v2 metadata modules and the latch snakemake command group are not present in the stable 2.77.1 source tree. The tutorial's generated Dockerfile also pins the workflow runtime separately to latch[snakemake]==2.55.0.a6.
Therefore:
- Re-check the official tutorial's exact pin before starting.
- Use an isolated environment.
- Preserve and review both the local CLI pin and generated runtime pin.
- Do not upgrade that environment to stable 2.77.1 without a migration plan.
- Do not copy v2 imports into a stable-track project.
- Treat the alpha pin as pre-release software and validate end to end.
Snakemake resource and environment rules
- Give every rule CPU and memory resources or define safe defaults in
profiles/default/config.yaml. - Pin Conda and container environments.
- Keep the Latch executor/storage plugin configuration from the chosen track.
- Use
LatchOutputDirfor output destinations exposed in the form. - Avoid embedding credentials in
environment.yaml, Dockerfiles, profiles, or generated metadata.
Generated-File Discipline
Before editing a generated file:
- Find the command and source file that generated it.
- Determine whether regeneration overwrites the file.
- Prefer the documented extension file.
- If customization of generated code is unavoidable, record the generation command and stop passing flags that regenerate it.
- Diff generated output after every SDK upgrade.
Release Checklist
- SDK and pipeline-engine versions are pinned.
- Schema/config and generated metadata are in sync.
- Every parameter has the expected type and default.
- Containers and package environments are immutable enough to reproduce.
- Small test data succeeds.
- Resume/cache behavior has been exercised.
- Shared storage has enough capacity and an intentional retention period.
- Result paths and execution reports appear in the Console.
- A clean registration from a fresh checkout works.
Official Sources
- Nextflow tutorial: https://wiki.latch.bio/workflows/sdk/nextflow/tutorial
- Nextflow overview: https://wiki.latch.bio/workflows/sdk/nextflow/overview
- Nextflow dependencies: https://wiki.latch.bio/workflows/sdk/nextflow/dependencies
- Nextflow profiles: https://wiki.latch.bio/workflows/sdk/nextflow/profiles
- Nextflow GPU guide: https://wiki.latch.bio/workflows/sdk/nextflow/gpus
- Nextflow shared storage: https://wiki.latch.bio/workflows/sdk/nextflow/shared-storage
- Snakemake v2 tutorial: https://wiki.latch.bio/workflows/sdk/snakemake-v2/tutorial
- Snakemake v2 overview: https://wiki.latch.bio/workflows/sdk/snakemake-v2/overview
- CLI source in the 2.77.1 release commit: https://github.com/latchbio/latch/blob/b3768e65c6d496868f6e530f11977d857ad85dc7/src/latch_cli/main.py
- Changelog in the 2.77.1 release commit: https://github.com/latchbio/latch/blob/b3768e65c6d496868f6e530f11977d857ad85dc7/CHANGELOG.md