当前位置: 首页 > Skill >

nextflow

nextflow

nextflow

端到端构建、运行并调试 Nextflow 数据流水线以及 nf-core 工作流。当用户提到 Nextflow、nf-core、.nf 文件、nextflow.

1.0.0 2026.11.13 114
获取Skill文件查看使用说明
作 者:沈禾 许可证: 更新时间:2026.11.13
本文目录展开

Nextflow

概述

Nextflow 是一种用于构建可复现、可移植、可扩展数据流水线的流程语言与运行时。它在生物信息学中占主导,但也适用于任何数据密集型计算。nf-core 是一个社区,在 Nextflow 之上维护生产级 Nextflow 流水线、可复用模块与 nf-core 工具链。

关键理念:

  • 数据流编程:流水线是由通道连接的 process 任务构成。Nextflow 从数据依赖推断执行顺序与并行度——无需编写显式调度器。
  • 一次编写,随处运行:同一流水线通过更改配置/配置文件(而非代码)即可在本地、HPC(SLURM、SGE、LSF、PBS)与云(AWS Batch、Google Batch、Azure Batch、Kubernetes)上运行。
  • 可复现性:按任务容器化(Docker/Singularity/Apptainer/Conda/Wave)+ -resume 缓存 + 固定的流水线版本。
  • DSL2 是现代、必需的语法:模块化的 process/workflow/include 定义。

本 skill 同时涵盖运行现有流水线,以及开发你自己的(Nextflow 语言 + nf-core 约定、用 nf-test 测试、配置与部署)。

何时使用本 Skill

在以下场景使用本 skill:

  • 运行 nf-core 或自定义 Nextflow 流水线,或调试失败/恢复的运行。
  • 编写或修改 .nf 脚本、nextflow.config、配置文件或 nextflow_schema.json。
  • 编写或测试 nf-core 风格模块/子工作流(main.nf、meta.yml、tests/、nf-test)。
  • 配置 executor、容器或资源;扩展到 HPC 或云。
  • 构建可复现的科学/生物信息学工作流(即使未指明“Nextflow”)。
  • 理解 process、channel、operator、take/emit、publishDir、ext.args、meta map。

安装

Nextflow 需要 Bash 与 Java 17 或更新(支持 17–25)。用 java -version 验证。

# 安装 Nextflow(自包含启动器)
curl -s https://get.nextflow.io | bash      # 创建 ./nextflow
sudo mv nextflow /usr/local/bin/             # 放入 PATH
nextflow info                                # 验证

# 或经 conda/bioconda(同时获得受管 Java)
conda create -n nf -c bioconda -c conda-forge nextflow nf-core
# nf-core 工具(Python)用于创建/lint/运行 nf-core 资产
pip install nf-core            # 或:conda install -c bioconda nf-core
nf-core --version

为可复现性固定引擎:export NXF_VER=24.10.0(仅在需要时使用 [edge] 版本)。对气隙/HPC,见 references/running-pipelines.md(离线模式)与 references/configuration.md。

两种工作路径

确定用户处在哪条路径上——这改变一切:

目标 从这里开始
运行现有流水线(nf-core 或给你的 .nf) references/running-pipelines.md
开发新流水线 / 模块 / 子工作流 references/language.md + references/developing.md
配置 / 扩展(HPC、云、容器、资源) references/configuration.md + references/containers.md
测试模块/流水线 references/testing.md

快速开始

运行 nf-core 流水线

始终先用自带的 test 配置文件做冒烟测试;它使用微小数据,验证你的环境可用。

# 1. 确认设置可用(下载流水线 + 微小测试数据)
nextflow run nf-core/rnaseq -profile test,docker --outdir results

# 2. 真实运行:固定版本(-r),选容器引擎,传入输入
nextflow run nf-core/rnaseq -r 3.14.0 
  -profile docker 
  --input samplesheet.csv 
  --genome GRCh38 
  --outdir results 
  -resume
  • -profile(单破折号)选择内置配置 profile;用逗号分隔组合它们,如 test,docker。容器/基础设施 profile(docker、singularity、conda)互斥——选一个。
  • --input、--genome、--outdir(双破折号)是流水线参数。nf-core 流水线接收 samplesheet CSV,而非散落文件。
  • -resume 复用上次运行的缓存结果。-r <version> 固定一个发布版本以保证可复现性。

用 nf-core pipelines launch <name> 以交互式、schema 校验的方式构建命令与 -params-file。见 references/running-pipelines.md。

编写最小流水线

#!/usr/bin/env nextflow

process SAYHELLO {
    tag "$greeting"
    publishDir "results", mode: 'copy'

    input:
    val greeting

    output:
    path "${greeting}.txt"

    script:
    """
    echo '$greeting world' > ${greeting}.txt
    """
}

workflow {
    channel.of('hello', 'bonjour', 'hola') | SAYHELLO
}
nextflow run main.nf            # 重跑时加 -resume

完整语言(process、channel、operator、带 take/main/emit 的 DSL2 workflow、module)见 references/language.md。

核心概念一瞥

  • Process:运行脚本(默认 Bash)的工作单元。声明 input:、output:、可选 directives(资源、容器、publishDir、tag、errorStrategy),以及 script:/shell:/exec: 块。每个任务在自身隔离的工作目录(work/xx/yy…)中运行。
  • Channel:连接 process 的异步队列。Queue channel 是可消费的流;value channel 持有单个可复用值。用 channel.of、channel.fromPath、channel.fromFilePairs、channel.value 等工厂创建。
  • Operator:转换/组合通道——map、filter、collect、groupTuple、join、combine、mix、flatten、branch、multiMap、splitCsv、view、set。
  • Workflow:组合 process。DSL2 workflow 可声明 take:(输入)、main:(逻辑)、emit:(命名输出),并作为子工作流被 include。未命名的 workflow {} 是入口点。
  • Module:通过 include { NAME } from './path'(支持 as 别名)暴露 process/workflow 的 .nf 文件。
  • Configuration:nextflow.config 设置 params、process 指令、executor、容器引擎与命名 profiles。选择器 withName:/withLabel: 针对特定 process。见 references/configuration.md。
  • meta map(nf-core):在输入/输出元组中,文件旁携带元数据 map([ id:'sample1', single_end:false ])的约定,使样本在流水线中保持标记。见 references/developing.md。

nf-core 工具 CLI

nf-core 工具(v3+)将子命令分组在 pipelines、modules、subworkflows 下。(nf-core lint 等裸形式仍可用但会警告——优先用分组形式。)

命令 用途
nf-core pipelines list 列出/搜索 nf-core 流水线(--json、关键字)
nf-core pipelines create 从 nf-core 模板搭建新流水线
nf-core pipelines launch <name> 交互式、schema 驱动的命令 + 参数文件
nf-core pipelines download <name> 下载流水线 + 容器供离线/HPC 使用
nf-core pipelines lint 按 nf-core 标准 lint 流水线(在仓库根目录运行)
nf-core pipelines schema build 通过 Web GUI 构建/编辑 nextflow_schema.json
nf-core pipelines create-params-file <name> 生成带文档的 YAML 参数文件
nf-core pipelines bump-version / sync 提升版本 / 与模板更新同步
nf-core modules list/info/install/update/remove 管理来自 nf-core/modules 的模块
nf-core modules create / lint / test 编写、lint 与 nf-test 一个模块
nf-core modules patch / bump-versions 修补已安装模块 / 提升工具版本
nf-core subworkflows install/create/lint/test 子工作流的相同生命周期

完整命令参考、标志与示例:references/nf-core-tools.md。

必要 nextflow CLI

命令 用途
nextflow run <pipeline> -profile <p> --outdir <dir> 运行流水线(路径、.nf 或 user/repo)
-resume 复用上次运行的缓存结果
-r <rev> 运行特定 git 修订/标签/分支
-params-file params.yml 从 YAML/JSON 提供参数
-c custom.config 叠加额外配置文件
-with-report -with-trace -with-timeline -with-dag flow.html 执行报告、trace、时间线、DAG
-stub-run 只运行 stub: 块(管线干跑)
nextflow log 检查过去的运行
nextflow clean -f -before <run> 删除旧 work/ 数据
nextflow pull / drop / list / info <repo> 管理缓存的远程流水线

配置、executor、缓存内部与追踪细节:references/configuration.md。

最佳实践(高价值习惯)

  • 始终先 test:真实数据前先用 -profile test,docker(或 singularity/conda)——快速且能捕获环境问题。
  • 固定一切:流水线版本(-r)、NXF_VER 与工具版本(容器)。不要对你将发表的科学运行 latest。
  • 使用 -resume 并理解缓存:任务在输入、脚本或容器变化时重跑。缓存调试见 references/configuration.md。
  • 通过 config/params-file 参数化,而非硬编码路径。将 params 与 profile 保留在 nextflow.config 中。
  • 每个 process 一个容器/conda 环境;绝不依赖主机上安装的工具。
  • nf-core 开发:写新模块前先复用现有模块(nf-core modules install);通过 ext.args 传递工具标志(而非硬编码在脚本中);始终包含 stub: 块与 nf-test 测试;提交前运行 nf-core pipelines lint 与 prettier。
  • 合理设置资源:用 process_low/medium/high 标签与 errorStrategy 'retry' 配合动态 task.attempt 扩展,而非一次性巨大请求。
  • 编写前向兼容语法:严格语法解析器在 Nextflow 26.04 成为默认。优先小写 channel.of(...)、显式闭包参数({ v -> ... })、所有变量用 def、以及 emit: 命名输出。用 nextflow lint 检查。

参考文件

需要深入时阅读相关文件——每个都自包含:

  • references/language.md — DSL2 语言:process、指令、channel、operator、workflow(take/emit)、module、动态资源、错误处理。
  • references/configuration.md — nextflow.config、作用域、profiles、withName/withLabel 选择器、executor(local/SLURM/cloud)、缓存/-resume 内部、追踪/报告、nextflow CLI。
  • references/containers.md — Docker、Singularity/Apptainer、Podman、Conda、Wave 容器;选择并启用引擎;常见陷阱。
  • references/running-pipelines.md — 查找/运行 nf-core 流水线、samplesheet、参数文件、参考基因组(iGenomes)、离线运行、机构配置、Seqera Platform。
  • references/nf-core-tools.md — 完整 nf-core CLI 参考(pipelines/modules/subworkflows)、标志与工作流。
  • references/developing.md — 编写 nf-core 流水线与模块:模板布局、模块 main.nf/meta.yml、meta map、ext.args/modules.config、子工作流、资源标签、lint 与 Harshil 对齐风格。
  • references/testing.md — 模块/子工作流/流水线的 nf-test:测试结构、断言、快照、标签、运行测试、CI。

官方文档:Nextflow https://www.nextflow.io/docs/latest/ · nf-core https://nf-co.re/docs/ · 训练 https://training.nextflow.io/

推荐文章

更多
PHP时间戳与日期字符串相互转换方法详解

本文介绍PHP中时间数值(Unix时间戳)与日期字符串之间的相互转换方法。通过strtotime和date函数,实现将当前时间、指定日期转换为时间戳,以及将时间戳格式化为可读的日期时间字符串,并提供相关在线计算工具推荐。

2025.11.30 1,016
PHP跨域配置:怎么安全地允许指定域名而非使用通配符

在 PHP 中安全地允许指定域名跨域,核心是解析请求头中的 Origin ,验证其是否在白名单内,然后动态设置 Access-Control-Allow-Origin 响应头。不要使用通配符 * ,也不要硬编码单一域名。

2025.03.29 1,004
JavaScript中利用replace结合正则实现replaceAll效果

JavaScript原生仅支持replace()进行单次或全局替换,缺乏类似Java的replaceAll()便捷方法。本文总结四种在JS中实现全量替换的方案:使用带g标志的正则、带gm标志的正则、扩展String原型以及split后join。通过对比代码示例,展示各方法的实现细节与适用场景,帮助开发者根据需求选择最优解。

2025.04.29 1,002
PHP日期转时间戳时区偏差怎么解决

在 PHP 中将日期字符串转换为时间戳时,若未显式指定时区,默认使用脚本配置的 date.timezone 或系统时区。当服务器时区与业务逻辑预期(如 UTC )不一致时,会产生偏差。解决核心是确保输入字符串携带明确时区信息,或在转换前统一设置时区上下文。

2026.10.24 1,001
PHP实现基础文件上传:HTML表单与$_FILES处理流程

在 HTML 表单中设置 enctype="multipart/form-data" ,并在 PHP 后端通过 $_FILES 数组接收文件,调用 move_uploaded_file() 将临时文件移动到目标目录即可完成上传。

2026.09.07 1,001
PHP集成RabbitMQ实现消息队列的完整步骤

使用 php-amqplib 库,通过建立连接、声明交换机与队列并绑定,即可在 PHP 中实现消息的发送与消费。

2026.05.24 1,001
Skill 文件
  • SKILL.md
    • Nextflow
    • 概述
    • 何时使用本 Skill
    • 安装
    • 两种工作路径
    • 快速开始
      • 运行 nf-core 流水线
      • 编写最小流水线
    • 核心概念一瞥
    • nf-core 工具 CLI
    • 必要 nextflow CLI
    • 最佳实践(高价值习惯)
    • 参考文件
  • 项目或源文件

相关 Skill

更多
service-qa-coach service-qa-coach Review support quality for chat, email, phone, social DM, or marketplace service teams. Use when a team needs a QA scorecard, failure-mode analysis, coaching plan, calibration checklist, or service-improvement brief without live ticketing, CRM, or contact-center system access.
高中数学作业批改助手 高中数学作业批改助手 >图片识别 直接读取学生手写作答照片,识别公式、符号、步骤 🧮 自动推导 根据题目自动生成参考答案和评分细则,无需教师预设 📊 逐步给分 每个关键步骤独立评分,体现过程分 📝 结构化报告 输出含识别内容、参考答案、逐步评分、改进建议的完整报告 🗂 批量批改 支持一次性批改多道题,最终汇总得分表
Vibration Analysis Vibration Analysis 分析来自CMS趋势、RMS/峰值、频谱及SCADA报警的风机传动链(主轴、齿轮箱、发电机)振动数据。
Traditional Bone Tool Making Basics Traditional Bone Tool Making Basics Use when you need custom, durable, repairable tools like awls, needles, scrapers, harpoons, or fishing hooks made from local animal bones or antlers and comm...
音频混音工具 音频混音工具 名称:Sound Mixing Tool(标识 sound-mixing-tool) 短简介(≤60字):音乐/音效响度精确对齐 + 融合混音工作流:用 ffmpeg 两段式 loudnorm 把多组素材 LUFS 偏差压到 <0.10,再最小干预融合、导出可进引擎的独立分轨。 标签/关键词:音频混音 响度匹配 LUFS ffmpeg 游戏音频 音效设计 Wwise FMOD 分轨导出 后期处理 触发词:混音 · 响度匹配 · LUFS 对齐 · MIX 版本 · 音乐音效分轨 · 融合 · 不打架 · 不能盖住 适用场景 :游戏音频集成、影视短视频配乐、播客后期