【问题标题】:Nextflow script to process all files in given directory用于处理给定目录中所有文件的 Nextflow 脚本
【发布时间】:2023-01-20 08:57:27
【问题描述】:

我有一个 nextflow 脚本,它在单个 vcf 文件上运行几个进程。文件名为“bos_taurus.vcf”,位于目录 /input_files/bos_taurus.vcf 中。目录 input_files/ 还包含另一个文件“sacharomyces_cerevisea.vcf”。我希望我的 nextflow 脚本能够处理这两个文件。我试图使用像 ch_1 = channel.fromPath("/input_files/*.vcf") 这样的 glob 模式,但遗憾的是我找不到可行的解决方案。任何帮助将非常感激。

#!/usr/bin/env nextflow

nextflow.enable.dsl=2


// here I tried to use globbing

params.input_files = "/mnt/c/Users/Lenovo/Desktop/STUDIA/BIOINFORMATYKA/SEMESTR_V/PRACOWNIA_INFORMATYCZNA/nextflow/projekt/input_files/*.vcf"

params.results_dir = "/mnt/c/Users/Lenovo/Desktop/STUDIA/BIOINFORMATYKA/SEMESTR_V/PRACOWNIA_INFORMATYCZNA/nextflow/projekt/results"


file_channel = Channel.fromPath( params.input_files, checkIfExists: true )


// how can I make this process work on two files simultanously

process FILTERING {

    publishDir("${params.results_dir}/after_filtering", mode: 'copy')

    input:
    path(input_files)

    output:
    path("*")

    script:
    """
    vcftools --vcf ${input_files} --mac 1 --minQ 20 --recode  --recode-INFO-all  --out after_filtering.vcf
    """
}

【问题讨论】:

    标签: bash groovy pipeline bioinformatics nextflow


    【解决方案1】:

    这是初学者的一个小例子。首先,您应该在每个进程中指定一个唯一的输出名称。目前,after_filtering.vcf 是硬编码的,因此一旦复制到 publishDir 就会相互覆盖。您可以使用 baseName 运算符执行此操作,如下所示,并将其作为映射永久存储在输入文件通道中,第一个元素是示例名称,第二个元素是实际文件。我制作了一个仅在 vcf 上运行 head 的示例过程,然后您可以根据需要根据实际需要进行调整。

    #! /usr/bin/env nextflow
    
    nextflow.enable.dsl = 2
    
    params.input_files = "/Users/atpoint/vcf/*.vcf"
    params.results_dir = "/Users/atpoint/vcf/"
    
    // A channel that contains a map with sample name and the file itself
    file_channel = Channel.fromPath( params.input_files, checkIfExists: true )
                          .map { it -> [it.baseName, it] }
    
    // An example process just head-ing the vcf
    process VcfHead {
    
        publishDir("${params.results_dir}/after_filtering", mode: 'copy')
    
        input:
        tuple val(name), path(vcf_in)
    
        output:
        path("*_head.vcf")
    
        script:
        """ 
        head -n 1 $vcf_in > ${name}_head.vcf
        """
    
    }                      
    
    // Run it
    workflow {
    
        VcfHead(file_channel)
    
    }
    

    file_channel 频道如果你添加一个 .view() 看起来像这样:

    [one, /Users/atpoint/vcf/one.vcf]
    [two, /Users/atpoint/vcf/two.vcf]
    

    【讨论】:

      猜你喜欢
      • 2013-10-06
      • 1970-01-01
      • 2021-09-27
      • 2016-10-07
      • 2012-03-12
      • 1970-01-01
      • 2018-10-29
      相关资源
      最近更新 更多