Skill Tracer
Skills › Scientific Agent Skills › latchbio-integration › nextflow-snakemake.md

nextflow-snakemake.md

258 lines · skills/latchbio-integration/references/nextflow-snakemake.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Nextflow and Snakemake Integration
2
3Latch supports Python, Nextflow, and Snakemake workflows, but their packaging
4paths are not interchangeable. Confirm the SDK version and choose one track
5before generating files.
6

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 6
7## Nextflow: Documented SDK Wrapper Path
8

Nextflow: Documented SDK Wrapper Path

Raw lines 7 to 8
9### Prerequisites
11- A runnable Nextflow pipeline
12- A `nextflow_schema.json`
13- Containers or a documented execution profile for every process
14- A pinned Latch SDK
16Install:
18```bash
19uv pip install "latch==2.77.1"
20```

Prerequisites

  • 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 21
22### Generate metadata
24```bash
25latch generate-metadata nextflow_schema.json --nextflow
26```
28Current generation creates:
30```text
31latch_metadata/
32├── __init__.py
33└── generated.py
34```
36- `generated.py` is regenerated from the schema. Do not edit it.
37- Put persistent custom metadata and flow changes in `latch_metadata/__init__.py`.
38- Re-run generation after changing `nextflow_schema.json`.
39- Review inferred file, enum, default, and required types before registration.
41SDK 2.67.0 changed Nextflow generation to use one generated dataclass containing
42all parameters and a generated base flow. Older `parameters.py` examples may no
43longer match the generated layout.

Generate metadata

latch generate-metadata nextflow_schema.json --nextflow

Current generation creates:

latch_metadata/
├── __init__.py
└── generated.py
  • generated.py is 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.

Raw lines 22 to 44
45### Register
47The currently documented wrapper command is:
49```bash
50latch login
51latch register . \
52 --nf-script main.nf \
53 --nf-execution-profile docker,test
54```
56Registration generates a Latch workflow wrapper and `latch.config`. The exact
57entrypoint location depends on the generation path and SDK version.
59Important:
61- If a root `Dockerfile` exists, registration uses it.
62- Otherwise Latch can generate a Dockerfile under `.latch/`.
63- Passing `--nf-script` again can regenerate and overwrite wrapper code.
64- After intentionally customizing a generated entrypoint, re-register without
65 `--nf-script` to preserve it.
66- Keep custom code in a separate module when possible.

Register

The currently documented wrapper command is:

latch login
latch register . \
  --nf-script main.nf \
  --nf-execution-profile docker,test

Registration generates a Latch workflow wrapper and latch.config. The exact entrypoint location depends on the generation path and SDK version.

Important:

  • If a root Dockerfile exists, registration uses it.
  • Otherwise Latch can generate a Dockerfile under .latch/.
  • Passing --nf-script again can regenerate and overwrite wrapper code.
  • After intentionally customizing a generated entrypoint, re-register without --nf-script to preserve it.
  • Keep custom code in a separate module when possible.
Raw lines 45 to 67
68### Generate an entrypoint explicitly
70SDK 2.77.1 also exposes:
72```bash
73latch nextflow generate-entrypoint . \
74 --nf-script main.nf \
75 --execution-profile docker,test \
76 --output wf/custom_entrypoint.py
77```
79This requires a valid `NextflowMetadata` object in the metadata root.

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.py

This requires a valid NextflowMetadata object in the metadata root.

Raw lines 68 to 80
81### Experimental Forch-only registration
83The CLI also has:
85```bash
86latch nextflow register . --script-path main.nf
87```
89The official CLI guide marks this command **experimental** and only applicable
90to Forch, Latch's architecture for running Nextflow in the user's own AWS
91account. It is not a general alternative to `latch register --nf-script`.
92Use it only for a configured Forch/BYOC project with current Latch guidance.

Experimental Forch-only registration

The CLI also has:

latch nextflow register . --script-path main.nf

The 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.

Raw lines 81 to 93
94### Nextflow configuration rules
96- Define every process container.
97- Use profiles for environment-specific settings rather than editing the
98 pipeline for Latch.
99- Keep Latch's generated `latch.config` in the effective config chain.
100- Use the official Latch shared-storage guidance for processes that need a
101 common work directory.
102- Configure private registries through Latch's supported credentials path.
103- Follow the Latch GPU guide for process accelerators; do not translate Python
104 task decorators into Nextflow resource syntax.
105- Set `NextflowRuntimeResources.storage_gib` for the runtime/shared filesystem,
106 not just final outputs.
107- Understand storage-retention cost before increasing
108 `storage_expiration_hours`.

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.config in 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_gib for the runtime/shared filesystem, not just final outputs.
  • Understand storage-retention cost before increasing storage_expiration_hours.
Raw lines 94 to 109
110### Debugging
112```bash
113latch register --staging .
114latch develop .
115latch nextflow attach --execution-id <execution-id>
116```
118Within `latch develop`, the production storage initializer is unavailable.
119Follow the official debug-mode guidance: use the local executor, bypass the
120initializer in debug mode, use a compatible Latch Nextflow base image, and
121reduce process resources.

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.

Raw lines 110 to 122
123## Snakemake: Choose a Compatibility Track
125The current docs and current stable package expose different Snakemake tracks.
126Do not mix them.

Snakemake: Choose a Compatibility Track

The current docs and current stable package expose different Snakemake tracks. Do not mix them.

Raw lines 123 to 127
128### Track A: legacy flags in 2.77.1 source (documentation conflict)
130The `2.77.1` wheel still exposes the `snakemake` extra, legacy metadata classes,
131`generate-metadata --snakemake`, and `register --snakefile`. However, the
132official CLI guide marks the Snakemake metadata and registration flags
133deprecated and says metadata generation no longer works for
134`latch >= 2.55.0.a6`.
136Treat this as an unresolved source/documentation conflict. The commands below
137are useful when maintaining a legacy project already known to use this path,
138but should not be presented as a supported new-project flow without confirming
139with current Latch documentation or support.
141Use Python 3.11 for the broadest compatibility with the pinned Snakemake 7.x
142dependency:
144```bash
145uv venv --python 3.11
146source .venv/bin/activate
147uv pip install "latch[snakemake]==2.77.1"
148```
150Generate metadata from the workflow config:
152```bash
153latch generate-metadata config.yaml --snakemake
154```
156Register:
158```bash
159latch register . --snakefile Snakefile
160```
162Relevant options:
164```bash
165latch register . \
166 --snakefile Snakefile \
167 --metadata-root latch_metadata \
168 --cache-tasks
169```
171Use the current `SnakemakeMetadata`, `SnakemakeParameter`, `FileMetadata`,
172`EnvironmentConfig`, and `DockerMetadata` APIs from `latch.types.metadata`.
173Inspect their signatures before generating hand-written metadata.

Track 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 --snakemake

Register:

latch register . --snakefile Snakefile

Relevant options:

latch register . \
  --snakefile Snakefile \
  --metadata-root latch_metadata \
  --cache-tasks

Use the current SnakemakeMetadata, SnakemakeParameter, FileMetadata, EnvironmentConfig, and DockerMetadata APIs from latch.types.metadata. Inspect their signatures before generating hand-written metadata.

Raw lines 128 to 174
Runs code bin/activate :146
175### Track B: official Snakemake v2 tutorial
177The current Snakemake v2 tutorial is a compatibility-specific path. At the time
178of this refresh, it explicitly requires:
180```bash
181uv venv --python 3.11
182source .venv/bin/activate
183uv pip install "latch==2.62.1a2"
184```
186It uses imports such as:
188```python
189from latch.types.metadata.snakemake_v2 import SnakemakeV2Metadata
190```
192and commands such as:
194```bash
195latch snakemake generate-entrypoint .
196latch dockerfile --snakemake -c environment.yaml . -f
197latch register -y .
198```
200Those v2 metadata modules and the `latch snakemake` command group are not
201present in the stable 2.77.1 source tree. The tutorial's generated Dockerfile
202also pins the workflow runtime separately to
203`latch[snakemake]==2.55.0.a6`.
205Therefore:
207- Re-check the official tutorial's exact pin before starting.
208- Use an isolated environment.
209- Preserve and review both the local CLI pin and generated runtime pin.
210- Do not upgrade that environment to stable 2.77.1 without a migration plan.
211- Do not copy v2 imports into a stable-track project.
212- Treat the alpha pin as pre-release software and validate end to end.

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 SnakemakeV2Metadata

and 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.
Raw lines 175 to 213
Runs code bin/activate :182
214### Snakemake resource and environment rules
216- Give every rule CPU and memory resources or define safe defaults in
217 `profiles/default/config.yaml`.
218- Pin Conda and container environments.
219- Keep the Latch executor/storage plugin configuration from the chosen track.
220- Use `LatchOutputDir` for output destinations exposed in the form.
221- Avoid embedding credentials in `environment.yaml`, Dockerfiles, profiles, or
222 generated metadata.

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 LatchOutputDir for output destinations exposed in the form.
  • Avoid embedding credentials in environment.yaml, Dockerfiles, profiles, or generated metadata.
Raw lines 214 to 223
224## Generated-File Discipline
226Before editing a generated file:
2281. Find the command and source file that generated it.
2292. Determine whether regeneration overwrites the file.
2303. Prefer the documented extension file.
2314. If customization of generated code is unavoidable, record the generation
232 command and stop passing flags that regenerate it.
2335. Diff generated output after every SDK upgrade.

Generated-File Discipline

Before editing a generated file:

  1. Find the command and source file that generated it.
  2. Determine whether regeneration overwrites the file.
  3. Prefer the documented extension file.
  4. If customization of generated code is unavoidable, record the generation command and stop passing flags that regenerate it.
  5. Diff generated output after every SDK upgrade.
Raw lines 224 to 234
235## Release Checklist
237- SDK and pipeline-engine versions are pinned.
238- Schema/config and generated metadata are in sync.
239- Every parameter has the expected type and default.
240- Containers and package environments are immutable enough to reproduce.
241- Small test data succeeds.
242- Resume/cache behavior has been exercised.
243- Shared storage has enough capacity and an intentional retention period.
244- Result paths and execution reports appear in the Console.
245- A clean registration from a fresh checkout works.

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.
Raw lines 235 to 246
247## Official Sources
249- Nextflow tutorial: https://wiki.latch.bio/workflows/sdk/nextflow/tutorial
250- Nextflow overview: https://wiki.latch.bio/workflows/sdk/nextflow/overview
251- Nextflow dependencies: https://wiki.latch.bio/workflows/sdk/nextflow/dependencies
252- Nextflow profiles: https://wiki.latch.bio/workflows/sdk/nextflow/profiles
253- Nextflow GPU guide: https://wiki.latch.bio/workflows/sdk/nextflow/gpus
254- Nextflow shared storage: https://wiki.latch.bio/workflows/sdk/nextflow/shared-storage
255- Snakemake v2 tutorial: https://wiki.latch.bio/workflows/sdk/snakemake-v2/tutorial
256- Snakemake v2 overview: https://wiki.latch.bio/workflows/sdk/snakemake-v2/overview
257- CLI source in the 2.77.1 release commit: https://github.com/latchbio/latch/blob/b3768e65c6d496868f6e530f11977d857ad85dc7/src/latch_cli/main.py
258- Changelog in the 2.77.1 release commit: https://github.com/latchbio/latch/blob/b3768e65c6d496868f6e530f11977d857ad85dc7/CHANGELOG.md

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
Raw lines 247 to 258