Nextflow:python脚本不保存输出

2024-09-29 23:22:29 发布

您现在位置: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 ✔

谢谢

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

我将输入文件更改为文件()。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之后的这个路径是我输入文件的路径,我不知道为什么(这个目录中没有任何更改)


Tags: 文件path目录txt脚本inputoutputmain
1条回答
网友
1楼 · 发布于 2024-09-29 23:22:29

使用“更改文件”频道输入的内容似乎有问题。如果“嫦娥文件”应该是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 ✔

如果上述内容没有帮助,请说明“更改文件”频道是如何创建的

相关问题 更多 >

    热门问题