Nextflow 没有这样的变量: id

huangapple go评论65阅读模式
英文:

Nextflow No such variable: id

问题

我正在尝试使用Nextflow执行我的第一个代码,我引入了2个成对的读取并希望执行bbduk函数。我不知道为什么我的代码不起作用。

我尝试了以下代码:

#!/usr/bin/env nextflow

/*
 * Pipeline Metagenomics, conda ambient Metagenomics_Nextflow
 */

nextflow.enable.dsl=2 // Nextflow版本

params.fq1 = "$HOME/../*{1}.fq.gz" // 可以在脚本中使用--fq1 <value>命令进行修改
params.fq2 = "$HOME/..//*{2}.fq.gz" // 可以在脚本中使用--fq2 <value>命令进行修改

/*
 * Check the quality of raw sequences
 */

process BBduk {

    input:
        tuple val(meta), path(reads)
    tag {meta.id}

    output:
        tuple val(meta), path('*.fq.gz'), emit: reads
        tuple val(meta), path('*.log'), emit: log

    script:
        def prefix = file("${meta.id}")
        def raw      = "in1=${reads[0]} in2=${reads[1]}"
        def trimmed  = "out1=${prefix}_1.fastq.gz out2=${prefix}_2.fastq.gz"
        """
        echo(${prefix})
        echo(${raw})
        echo(${trimmed})
        bbduk.sh \\
        $raw \\
        $trimmed \\
        qtrim=r trimq=10 minlen=100 \\
        &> ${prefix}.bbduk.log
        """
}
/*
* Workflow
*/
workflow {
    sequences = Channel.fromFilePairs( [params.fq1,params.fq2] )
    println "Performing Quality control and triming from $sequences" 
    BBduk(sequences)
}

该代码在终端中产生以下错误。

ERROR ~ Error executing process > 'BBduk (1)'

Caused by:
  No such variable: id -- Check script 'Workflow_Clean_Human_DNA.nf' at line: 34

Source block:
  def prefix = file("${meta.id}")
  def raw      = "in1=${reads[0]} in2=${reads[1]}"
  def trimmed  = "out1=${prefix}_1.fastq.gz out2=${prefix}_2.fastq.gz"
  """
  echo(${prefix})
  echo(${raw})
  echo(${trimmed})
  bbduk.sh \\
  $raw \\
  $trimmed \\
  qtrim=r trimq=10 minlen=100 \\
  &> ${prefix}.bbduk.log
  """

代码的思想是对原始读取执行bbduk算法,我尝试了一对工作。我想在Nextflow中执行它,因为想将输出与其他算法链接在一起。

谢谢!

英文:

I'm trying to perform my first code with Next-flow, im introducing 2 paired reads and I want to execute the bbduk function. I don't know why my code didn't works.

I tryed the following code:

  #!/usr/bin/env nextflow


/*
 * Pipeline Metagenomics, conda ambient Metagenomics_Nextflow
 */

 nextflow.enable.dsl=2 // Nextflow version

params.fq1 = &quot;$HOME/../*{1}.fq.gz&quot; // Can be modified in the script with the --fq1 &lt;value&gt; command
params.fq2 = &quot;$HOME/..//*{2}.fq.gz&quot; // Can be modified in the script with the --fq2 &lt;value&gt; command
/*
 * params.out = &#39;OTU.tsv&#39;		// result file
 * params.databaseHuman = &quot;$baseDir/Database/GRCh38&quot; // 
 */

/*
 * Check the quality of raw sequences
 */

 process BBduk {

    input:
        tuple val(meta), path(reads)
    tag {meta.id}

    output:
        tuple val(meta), path(&#39;*.fq.gz&#39;), emit: reads
        tuple val(meta), path(&#39;*.log&#39;), emit: log
    
     script:
        def prefix = file(&quot;${meta.id}&quot;)
        def raw      = &quot;in1=${reads[0]} in2=${reads[1]}&quot;
        def trimmed  = &quot;out1=${prefix}_1.fastq.gz out2=${prefix}_2.fastq.gz&quot;
        &quot;&quot;&quot;
        echo(${prefix})
        echo(${raw})
        echo(${trimmed})
        bbduk.sh \\
        $raw \\
        $trimmed \\
        qtrim=r trimq=10 minlen=100 \\
        &amp;&gt; ${prefix}.bbduk.log
        &quot;&quot;&quot;

 }
/*
* Workflow
*/
workflow {
sequences = Channel.fromFilePairs( [params.fq1,params.fq2] )
println &quot;Performing Quality control and triming from $sequences&quot; 
    BBduk(sequences)
}   

The code produce the following error in terminal.

 ERROR ~ Error executing process &gt; &#39;BBduk (1)&#39;

Caused by:
  No such variable: id -- Check script &#39;Workflow_Clean_Human_DNA.nf&#39; at line: 34

Source block:
  def prefix = file(&quot;${meta.id}&quot;)
  def raw      = &quot;in1=${reads[0]} in2=${reads[1]}&quot;
  def trimmed  = &quot;out1=${prefix}_1.fastq.gz out2=${prefix}_2.fastq.gz&quot;
  &quot;&quot;&quot;
          echo(${prefix})
          echo(${raw})
          echo(${trimmed})
          bbduk.sh \\
          $raw \\
          $trimmed \\
          qtrim=r trimq=10 minlen=100 \\
          &amp;&gt; ${prefix}.bbduk.log
          &quot;&quot;&quot;

Tip: you can try to figure out what&#39;s wrong by changing to the process work dir and showing the script file named `.command.sh`

 -- Check &#39;.nextflow.log&#39; file for details

The idea of the code is to perform a bbduk algorithm into raw reads, I tried to perform a duple to work. I wan't to do it in next flow because the idea is chain the output with other algorithm

Thanks!

答案1

得分: 0

fromFilePairs工厂方法发出元组,其中第一个元素是分组键(第二个元素是匹配文件的列表)。它是一个简单的字符串(java.lang.String),而不是元数据映射。我认为你所需的只是类似以下的东西:


process BBduk {

    tag { sample_id }

    input:
    tuple val(sample_id), path(reads, stageAs: 'reads/*')

    output:
    tuple val(sample_id), path("${sample_id}_{1,2}.fq.gz"), emit: reads
    tuple val(sample_id), path("${sample_id}.bbduk.log"), emit: log

    script:
    def (fq1, fq2) = reads

    """
    bbduk.sh \\
        in1="${fq1}" \\
        in2="${fq2}" \\
        out1="${sample_id}_1.fq.gz" \\
        out2="${sample_id}_2.fq.gz" \\
        qtrim=r \\
        trimq=10 \\
        minlen=100 \\
        &>> "${sample_id}.bbduk.log"
    """
}

    reads = Channel.fromFilePairs( params.reads )

    BBduk( reads )
}

请注意,通过将文件放置在子目录中(使用stageAs: 'reads/*'),我们确保不会意外覆盖工作目录中的输入文件。

英文:

The fromFilePairs factory method emits tuples in which the first element is the grouping key (and the second element is the list of matching files). It is a simple String (java.lang.String), not a Map of meta data. I think all you need is something like:

params.reads = &#39;./*_{1,2}.fq.gz&#39;


process BBduk {

    tag { sample_id }

    input:
    tuple val(sample_id), path(reads, stageAs: &#39;reads/*&#39;)

    output:
    tuple val(sample_id), path(&quot;${sample_id}_{1,2}.fq.gz&quot;), emit: reads
    tuple val(sample_id), path(&quot;${sample_id}.bbduk.log&quot;), emit: log

    script:
    def (fq1, fq2) = reads

    &quot;&quot;&quot;
    bbduk.sh \\
        in1=&quot;${fq1}&quot; \\
        in2=&quot;${fq2}&quot; \\
        out1=&quot;${sample_id}_1.fq.gz&quot; \\
        out2=&quot;${sample_id}_2.fq.gz&quot; \\
        qtrim=r \\
        trimq=10 \\
        minlen=100 \\
        &amp;&gt; &quot;${sample_id}.bbduk.log&quot;
    &quot;&quot;&quot;
}
workflow {

    reads = Channel.fromFilePairs( params.reads )

    BBduk( reads )
}

Note that by staging the files in a subdirectory (using stageAs: &#39;reads/*&#39;), we ensure we don't accidentally clobber our input files in the working directory.

huangapple
  • 本文由 发表于 2023年7月20日 16:57:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76728240.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定