python - 找不到snakemake线程通配符

标签 python bioinformatics snakemake

我有一个蛇形规则,例如:

rule get_coverage:
    input: 
        cram=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome], #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'), 
        bai=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome] + '.crai', #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'),
        ref=lambda wildcards: config['reference_genome'][wildcards.reference_genome],
        chrom_size=lambda wildcards: config['chrom_size'][wildcards.reference_genome]
    output: 
        coverage=directory(config['output']['median_coverage'])
    conda: 
        src + '/env/acc_mask.yml'
    threads: 19
    script: 
        """
        mosdepth \
            -n \
            -t {threads} \
            --use-median \
            -f {input.ref} \
            -b {input.chrom_size} \
            {output.median_coverage} \
            {input.cram}
        """

我收到一个错误:

RuleException:
NameError in line xxx of xxx.smk:
The name 'threads' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be ...

在我的印象中,线程作为通配符,在shell中是可以被替换的。我的脚本有什么问题吗?

最佳答案

您是正确的,{threads} 可以在 shell 指令中使用。但是它不能在 script 指令中使用。您的规则包含后者,因此修复它应该可以使其工作:

rule get_coverage:
    input: 
        cram=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome], #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'), 
        bai=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome] + '.crai', #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'),
        ref=lambda wildcards: config['reference_genome'][wildcards.reference_genome],
        chrom_size=lambda wildcards: config['chrom_size'][wildcards.reference_genome]
    output: 
        coverage=directory(config['output']['median_coverage'])
    conda: 
        src + '/env/acc_mask.yml'
    threads: 19
    shell: 
        """
        mosdepth \
            -n \
            -t {threads} \
            --use-median \
            -f {input.ref} \
            -b {input.chrom_size} \
            {output.median_coverage} \
            {input.cram}
        """

关于python - 找不到snakemake线程通配符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76109079/

相关文章:

python - 如何使用 ephem 库在 python 中确定它是否是白天(外面有光?)

javascript - 从子序列中寻找超序列的多数合并算法的实现?

r - 根据行和列元数据将 data.frame 中的一个值除以备用 data.frame 中的另一个值

snakemake - 在 cluster.yaml 文件中访问 jobid

python - 使用适用于 Visual Studio 的 Python 工具在 Visual Studio 中使用 Matplotlib 绘图

python - Dask dataframe 基于列或函数分割分区

python - 读取内置的 python 模块

python - 获取遗传算法中使用的对象的值

snakemake - Snakemake 中带有空格的文件

python - 使用snakemake从多个文件夹移动和重命名文件