Nextflow:python脚本不保存输出

问题描述

我在Nextflow中使用Python脚本遇到问题,我的目标是在python脚本中编写一个文件,然后在nextflow中使用它,然后将文件保存在publishdir中(在其他过程中使用此文件之后)。 我在nextflow中的过程是这样的(文件是在之前定义的):

process writefile{
publishDir "${params.output_dir}/formatted",mode: 'copy'
input:
path file from change_file
output:
path "formattedfile.txt" into file_changed
script:
"""
file2formattedfile.py ${file} formattedfile.txt
"""
}

python脚本:(我简化了实际过程,但本质是这样的),我需要在nextflow中获取保存在输出文件中的文件

#!/usr/bin/env python3
import argparse
from sys import argv
def main():
   input,output = argv[1:3] 
   out = open(output,"w") 
   #My real operations are here
   out.write("Operations and text") 
   out.close() 

if __name__ == "__main__":
   main()

问题在于文件未保存在发布目录中,而是在nextflow的目录工作中,当我运行工作流时,该过程已完成而没有错误,但表示DataflowQueue(queue = [])

[e1/74e0ee] process > writefile (DataflowQueue(queue=[])) [100%] 1 of 1 ✔

谢谢!

-------------更新-------------

我将输入文件更改为file()。 nextflow.config

params {
  input_file = 'data/old_file.txt'
  output_dir = 'output_new'
}

main.nf

change_file = file(params.input_file)
process writefile{
publishDir "${params.output_dir}/formatted",mode: 'copy'
input:
path file from change_file
output:
path "formattedfile.txt" into file_changed
script:
"""
file2formattedfile.py ${file} formattedfile.txt
"""
}

这更改了nextflow的输出,但是我的输入文件不在发布目录中(而是在目录工作中)。

[7d/78559b] process > writefile (/home/myuser/Documentos/dir/pipeline_dir/data/old_file.txt) [100%] 1 of 1 ✔

writefile之后的路径是我的输入文件所在的路径,我不知道为什么(此目录中没有任何更改)。

解决方法

使用'change_file'通道输入的内容似乎有问题。如果'change_file'应该为value channel,请考虑以下事项:

params.change_file = 'my_change_file.txt'
params.output_dir = 'my_output_dir'

change_file = file(params.change_file)


process writefile{

    publishDir "${params.output_dir}/formatted",mode: 'copy'

    input:
    path infile from change_file

    output:
    path "formattedfile.txt" into file_changed

    """
    file2formattedfile.py "${infile}" formattedfile.txt
    """
}

结果:

[d6/5173c1] process > writefile [100%] 1 of 1 ✔

如果上述方法无济于事,请说明如何创建“ change_file”频道。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...