You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Nextflow中Bowtie2索引路径构建错误问题求助

问题描述

我在Nextflow流水线中运行Bowtie2比对时,遇到Bowtie2无法找到索引文件的错误,提示“reference_index.1.bt2不存在或不是Bowtie2索引”。我尝试动态提取Bowtie2参考索引的基名,用于bowtie2命令的-x选项,但路径构建出现问题。

我的代码

// Define the process for Bowtie2 alignment
process bowtie2 {

    input:
    path bowtie2_out
    path trimmomatic_out

    output:
    path "${params.outputDir8}/out.sam"

    script:
    """
    baseName=$(basename $(find ${bowtie2_out} -name '*.bt2' | head -n 1) | sed 's/\.[0-9]*\.bt2$//')
    indexPath="${bowtie2_out}/${baseName}"
   
    bowtie2 -x ${indexPath} \
            -1 ${trimmomatic_out}/output_1P.fq \
            -2 ${trimmomatic_out}/output_2P.fq \
            -S ${params.outputDir8}/out.sam
    """
}

错误信息

ERROR ~ Error executing process > 'bowtie2'

Caused by:
  Process `bowtie2` terminated with an error exit status (255)


Command executed:

  baseName=$(basename $(find reference_index.1.bt2 reference_index.2.bt2 reference_index.3.bt2 reference_index.4.bt2 reference_index.rev.1.bt2 reference_index.rev.2.bt2 -name '*.bt2' | head -n 1) | sed 's/\.[0-9]*\.bt2$//')
  indexPath="reference_index.1.bt2 reference_index.2.bt2 reference_index.3.bt2 reference_index.4.bt2 reference_index.rev.1.bt2 reference_index.rev.2.bt2/${baseName}"
  echo "Index path is: ${indexPath}"
  bowtie2 -x ${indexPath}             -1 trimmomatic_out/output_1P.fq             -2 trimmomatic_out/output_2P.fq             -S bowtie2_out/out.sam

Command exit status:
  255

Command output:
  Index path is: reference_index.1.bt2 reference_index.2.bt2 reference_index.3.bt2 reference_index.4.bt2 reference_index.rev.1.bt2 reference_index.rev.2.bt2/reference_index

Command error:
  Index path is: reference_index.1.bt2 reference_index.2.bt2 reference_index.3.bt2 reference_index.4.bt2 reference_index.rev.1.bt2 reference_index.rev.2.bt2/reference_index
  (ERR): "reference_index.1.bt2" does not exist or is not a Bowtie 2 index
  Exiting now ...

Work dir:
  /mnt/d/somil_ILBS/work/work/b3/358c00e746858cc5c99a755b28eba2

Tip: you can replicate the issue by changing to the process work dir and entering the command `bash .command.run`

 -- Check '.nextflow.log' file for details
解决方案

问题根源

从错误输出可以看到,输入的bowtie2_out是所有索引文件的列表,而非索引文件所在的目录。这导致find命令错误地将这些文件名当作搜索路径,最终拼接出的indexPath变成了无效的路径格式。

修正步骤

  1. 调整输入参数:确保bowtie2_out传递的是索引文件所在的目录,而非单个或多个索引文件。Nextflow会自动将整个目录同步到工作目录中。
  2. 简化基名提取逻辑:不需要用find,直接从目录下的索引文件提取基名,同时兼容rev后缀的索引文件:

修改后的完整代码:

process bowtie2 {

    input:
    path bowtie2_index_dir  // 重命名参数,明确是目录输入
    path trimmomatic_out

    output:
    path "${params.outputDir8}/out.sam"

    script:
    """
    # 获取目录下第一个bt2索引文件
    index_file=$(ls ${bowtie2_index_dir}/*.bt2 | head -n 1)
    # 提取基名,兼容普通索引和rev索引的命名格式
    baseName=$(basename ${index_file} | sed -E 's/\.(rev\.?)?[0-9]+\.bt2$//')
    indexPath="${bowtie2_index_dir}/${baseName}"
   
    bowtie2 -x ${indexPath} \
            -1 ${trimmomatic_out}/output_1P.fq \
            -2 ${trimmomatic_out}/output_2P.fq \
            -S ${params.outputDir8}/out.sam
    """
}

额外优化

如果你的Bowtie2索引基名是已知的(比如固定为reference_index),可以直接硬编码基名,避免动态提取的潜在问题,让代码更稳定:

// 替换script块中的路径构建部分
indexPath="${bowtie2_index_dir}/reference_index"

内容的提问来源于stack exchange,提问作者somilsharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 15:23:09