我有一个蛇形规则,例如:
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/