如何链接两个nexflow脚本,其中第一个脚本的输出输入到第二个

问题描述 投票:0回答:1

所以到目前为止我有两个 nextflow 脚本,第一个是

parse_annotation.nf
,它生成一个
.csv
文件,然后作为
sample_parse.nf
的输入。现在到目前为止,我已经从示例中弄清楚了如何作为独立工作流程运行。

现在我的目标是将它们放在一起,以便 首先运行

parse_annotation.nf
,然后其输出将被作为
sample_parse.nf
的输入,这将生成输出,我已经测试了 python 脚本,它工作正常。

parse_annotation.nf
#!/usr/bin/env nextflow

// Check if files exist
println "Checking file existence..."
println "parse_annotation.py exists: ${file('parse_annotation.py').exists()}"
println "sample_annot.txt exists: ${file('sample_annot.txt').exists()}"

// Print current working directory
println "Current working directory: ${System.getenv('PWD')}"

// Define the input annotation file channel
annotation_ch = Channel.fromPath(params.annotation_file)

// Define the process that runs the parse_annotation.py script
process parse_annotation {
    input:
        path annotation_file

    output:
        path "sample.csv"

    script:
        """
        python3 /home/krushna/temp/parse_annotation.py -f $annotation_file > sample_output.txt 2>&1
        """
}

// Run the process
workflow {
    parse_annotation(annotation_ch)
}

sample_parse.nf
#!/usr/bin/env nextflow

// Define input file parameters
params.csv_file = null
params.annot_file = null

// Check if files exist
println "Checking file existence..."
println "sample_parse.py exists: ${file('sample_parse.py').exists()}"
println "CSV file exists: ${file(params.csv_file).exists()}"
println "Annotation file exists: ${file(params.annot_file).exists()}"

// Define the input file channels
csv_ch = Channel.fromPath(params.csv_file)
annot_ch = Channel.fromPath(params.annot_file)

// Combine the input file channels
input_files = csv_ch.combine(annot_ch)

// Define the process that runs the sample_parse.py script
process parse_sample {
    input:
    tuple path(csv_file), path(annot_file)

    output:
    path "parsed_output_dir"

    script:
    """
    mkdir parsed_output_dir
    python3 /home/krushna/temp/sample_parse.py $csv_file $annot_file
    mv *.samplesheet.csv *.info.txt parsed_output_dir/
    """
}

// Run the process
workflow {
    parse_sample(input_files)
}

任何具有 DSL-2 格式的模板示例都会非常有帮助和赞赏

nextflow
1个回答
0
投票

看起来您只需要第三个 nf 文件/工作流程来使用您描述的那些流程。假设您的所有文件都位于同一文件夹中:

main.nf:

#!/usr/bin/env nextflow
include { parse_annotation } from "./parse_annotation.nf"
include { sample_parse } from "./sample_parse.nf"

workflow {
    annotation_ch = Channel.fromPath(params.annotation_file)
    csv_ch = parse_annotation(annotation_ch)
    parse_input = csv_ch.combine(annot_ch)
    sample_parse(parse_input)
}

现在您可以看到,这并没有考虑每个流程文件中的代码,这些代码已经加载到每个流程的文件匿名工作流的输入中。这可能会导致问题。也许您只是想将这些代码全部删除,如果它只是为了演示每个进程单独工作的话。否则,您可以保留该代码和这些工作流程,但将所有代码移至相应的

workflow { ... }
块内,以便仅在直接运行单个进程 .nf 文件时才会执行。 例如
parse_annotation.nf
看起来像这样:

#!/usr/bin/env nextflow

process parse_annotation { 
   ...
}

workflow {
   println "Checking file existence..."
   ...
   annotation_ch = Channel.fromPath(params.annotation_file)
   parse_annotation(annotation_ch)
}

}

© www.soinside.com 2019 - 2024. All rights reserved.