英文:
How to read dictionary input into snakemake
问题
我有输入的fastq文件在文件夹里。我想在snakemake中访问它。有人可以建议我如何访问它吗?
这是我迄今为止尝试过的代码。
infile_loc = {"Sample1":["/home/joshua/snakemake_works/input/Sample1_R1.fq.gz","/home/joshua/snakemake_works/input/Sample1_R2.fq.gz"], "Sample2":["/home/joshua/snakemake_works/input/Sample2_R1.fq.gz","/home/joshua/snakemake_works/input/Sample2_R2.fq.gz"]}
SAMPLES=infile_loc.keys()
rule print_file_name:
input:
expand("{sample}", sample=SAMPLES)
params:
read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
script:
"""
echo {params.read1}
echo {params.read2}
"""
但我得到了以下错误。
在文件/home/joshua/snakemake_works/Snakefile的第9行中的NameError:
名称'read1'未定义
File "/home/joshua/snakemake_works/Snakefile", line 9, in <module>
有人可以指导我如何解决这个错误吗?
英文:
I have input fastq files inside dictionary. I want to access it inside snakemake. Could anyone please suggest me how I can access it?
Here is the code that I've tried so far.
infile_loc = {"Sample1":["/home/joshua/snakemake_works/input/Sample1_R1.fq.gz","/home/joshua/snakemake_works/input/Sample1_R2.fq.gz"], "Sample2":["/home/joshua/snakemake_works/input/Sample2_R1.fq.gz","/home/joshua/snakemake_works/input/Sample2_R2.fq.gz"]}
SAMPLES=infile_loc.keys()
rule print_file_name:
input:
expand("{sample}", sample=SAMPLES)
params:
read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
script:
"""
echo {params.read1}
echo {params.read2}
"""
But I'm getting the following error.
NameError in file /home/joshua/snakemake_works/Snakefile, line 9:
name 'read1' is not defined
File "/home/joshua/snakemake_works/Snakefile", line 9, in <module>
Could anyone please guide me how I can resolve this error?
答案1
得分: 2
我认为问题在于您使用了 script
指令,而您应该改用 shell
指令。
rule print_file_name:
input:
expand("{sample}", sample=SAMPLES)
params:
read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
shell: # <------- 将 script 改为 shell
"""
echo {params.read1}
echo {params.read2}
"""
英文:
I think the problem is that you use the script
directive, and you should use the shell
directive instead.
rule print_file_name:
input:
expand("{sample}", sample=SAMPLES)
params:
read1, read2 = lambda wildcards: infile_loc[wildcards.sample]
shell: # <------- script changed to shell
"""
echo {params.read1}
echo {params.read2}
"""
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论